![]() |
Smooth 301 redirect php script
I need a smooth 301 redirect php script. More specifically, I am looking for a script that does the following:
Visitor goes to the page yourSite1.com/animal/dog/1.html. The visitor gets 301-redirected to yourSite2.com/animal/dog/1.html. How do I do this in php? |
Does it have to be php? You could set this up with apache using htaccess. A simple
Quote:
|
php or .htaccess.
Well actually, I need to remap number of pages. |
Quote:
|
If you really want to use php, there are several ways to do it. The simplist is with a straight 301 redirect with
Quote:
A more flexible method is to use a map. The advantage of this is that it has a default URL that redirects, typically, to your home page (prevents loss of traffic when pages are moved or deleted). In addition, the map allows you to effectively redirect from multiple URL's to there new location. Code:
<?php You should save this as error.php in the root directory of your site, and then add an .htaccess file with the following directive : ErrorDocument 404 /error.php That is just to handle 404 errors, you can also add additional error codes if you wish. With this script, if there is no map for the missing page, then you get 301 redirected to the home page of the site. However, if the missing page is one of the pages mapped in the map array, the script will 301 redirect you to that page instead. These scripts are most useful when the new loocation on your site does not mirror the structure of the original location. HTH |
Quote:
|
Oops, just spotted a typo, and I can't edit the original post. Please ignore the above script and use :-
Code:
<?php Also, it is possible to use .htaccess to redirect all files in one location to another, providing the directory structure of the destination remains the same. But the last time I tried that, I got lots of odd problems occuring with other SEO rules in the .htaccess file, so I changed to using the php script instead, which is much easier to maintain IMO. |
This doesn't work well if there are a couple of thousand pages to redirect, does it?
|
Not for a simple domain redirect, no. Sorry, I should have given you the exact code to use. I got myself muddled as to what you actually wanted. I would try this :-
Code:
|
Smooth 301 redirect php script
This doesn't work well if there are a couple of thousand pages to redirect, does it?
|
All times are GMT -5. The time now is 10:51 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
HTML Help provided by HTML Help Central.