301 redirection
Moderator: General Moderators
301 redirection
Hello Friends.. how r u all? Ahsan here.. am a newbie to PHP... I am stuck in a problem and I think this is the best platform for discussing issues related to PHP and getting quality solutions..Okay now lets talk about the issue.. I have a website of which i changed the domain name recently.. so now I want all my website visitors, that are requesting a particular page (or the index page) on the old domain, to be redirected (permanently i.e. with 301 header) to the corresponding page on the new domain but with the lower case i.e http://www.olddomain.com/AHSAN/ is redirected to http://www.newdomain.com/ahsan/. In addition to this, I also want to have my old domain in Google webmaster tools i.e. to verify the ownership of my old domain. Now what I did is that I made a .htaccess file as follows :
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
The redirection is working fine but the script is not lowering the case of the URL i.e. http://www.olddomain.com/AHSAN/ is redirected to http://www.newdomain.com/AHSAN/ instead of http://www.newdomain.com/ahsan/ and also Google is not able to verify the ownership of mine for my old domain.. Here I want to mention that I am verifying my website through the "uploading file" method so when google tries to access that file on the old domain it is redirected to the new domain. I hope I am clear with my query.. If I am not, please let me know.. Hope to get the solution soon.
Regards
Ahsan
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
The redirection is working fine but the script is not lowering the case of the URL i.e. http://www.olddomain.com/AHSAN/ is redirected to http://www.newdomain.com/AHSAN/ instead of http://www.newdomain.com/ahsan/ and also Google is not able to verify the ownership of mine for my old domain.. Here I want to mention that I am verifying my website through the "uploading file" method so when google tries to access that file on the old domain it is redirected to the new domain. I hope I am clear with my query.. If I am not, please let me know.. Hope to get the solution soon.
Regards
Ahsan
- daedalus__
- DevNet Resident
- Posts: 1925
- Joined: Thu Feb 09, 2006 4:52 pm
Re: 301 redirection
im not sure if you can change the case with mod rewrite but you sure can using php
Re: 301 redirection
Can you guide me how to do that in PHP? A Code example can be extremely handy and helpful..!
Re: 301 redirection
To route everything through PHP,
and then
Code: Select all
RewriteRule ^/?(?!redirect.php) /redirect.php [L]Code: Select all
<?php
$request = $_SERVER["REQUEST_URI"];
$request = strtok($request, "?") . "?" . strtok(""); // only lowercase the path
$request = strtolower(rtrim($request, "?")); // remove any trailing ?s
header("Location: http://www.newdomain.com{$request}");
header("HTTP/1.1 301 Moved Permanently");
exit;Re: 301 redirection
I put
in .htaccess
and
in redirect.php
but its not working
any other suggestion ?
Code: Select all
RewriteRule ^/?(?!redirect.php) /redirect.php [L]and
Code: Select all
<?php
$request = $_SERVER["REQUEST_URI"];
$request = strtok($request, "?") . "?" . strtok(""); // only lowercase the path
$request = strtolower(rtrim($request, "?")); // remove any trailing ?s
header("Location: http://www.newdomain.com{$request}");
header("HTTP/1.1 301 Moved Permanently");
exit;
?>but its not working
Re: 301 redirection
Care to elaborate?imahsan wrote:but its not working
And how about you post exactly what you have in both files.
Re: 301 redirection
Temporarily my .htaccess file look as follows:
With the above code redirection is working fine but not with the lower case and also Google verification issue.
Then i replace my code with what you suggested, that made my .htaccess file as follows:
and redirect.php file as :
but its showing:
500 Internal Server Error (?)
Code: Select all
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]With the above code redirection is working fine but not with the lower case and also Google verification issue.
Then i replace my code with what you suggested, that made my .htaccess file as follows:
Code: Select all
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^/?(?!redirect.php) /redirect.php [L]Code: Select all
<?php
$request = $_SERVER["REQUEST_URI"];
$request = strtok($request, "?") . "?" . strtok(""); // only lowercase the path
$request = strtolower(rtrim($request, "?")); // remove any trailing ?s
header("Location: http://www.newdomain.com{$request}");
header("HTTP/1.1 301 Moved Permanently");
exit;
?>but its showing:
500 Internal Server Error (?)
Re: 301 redirection
I wonder if the Rule should be
Code: Select all
RewriteRule ^/?(?!redirect.php) redirect.php [L]Re: 301 redirection
but when i did as you suggested its showing internal server error!!
Re: 301 redirection
Still the same internal server error 