1

I moved my site and I want to use the old site. The best way to use both is to show the current pages, if there is no page, redirect to the same address on the new site.

Can I do this only from the .htaccess file from old site?

If I can't do this, I think of another way to come. I can redirect 404 pages to the 404.php file on the new site. Can I then redirect the same URL using http_referer with the 404.php file?

  • What kind of site is your "old" site? Does it consist of static HTML/PHP documents or is it database driven like WordPress? If it's database driven (like WordPress) then you can't do this in .htaccess. – MrWhite Sep 1 '17 at 21:50
  • @MrWhite, I'm using WordPress, i understand. Can I do it with 404.php file? – İsmail Sep 1 '17 at 22:00
1

Since this is a database driven site then you can't do this type of redirect in .htaccess. Since it's not known that a request would result in a 404 until much later in the request (until after the database has been queried).

However, you can do this in your CMS's 404 template (eg. 404.php in WordPress).

For example:

<?php
// Redirect all requests that don't resolve on the old site to the new site
header('Location: http://example.com'.$_SERVER['REQUEST_URI'],true,302);
exit;

Where example.com is the domain of your new site.

Change the 302 to 301 only when you are sure it's working OK.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.