Mobile app version of vmapp.org
Login or Join
Jessie594

: If there is no page, redirecting to the other site 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

@Jessie594

Posted in: #301Redirect #Apache #Htaccess #Php

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?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Jessie594

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo487

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: 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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme