Forum Moderators: phranque
For example when someone requests
[olddomain2.com...]
they should be redirected (permanently) to
[newdomain.com...]
This is what I have in the .htaccess file:
Options All -Indexes +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.olddomain1\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^olddomain1\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.olddomain2\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^olddomain2\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.olddomain3\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^olddomain3\.com$ [NC,OR]
RewriteRule (.*) [newdomain.com...] [R=301,L]
My problem is, when I browse to a web page the domain name replacement happens but the path and file name of the page is transformed into lowercase. Naturally this doesn't work as the web server is case sensitive.
For example, when I browse to:
[olddomain2.com...]
I receive:
[newdomain.com...]
Could someone please help me to correct the .htaccess file so that I have permanent redirections from the old domain names but preserves the case of the path and filename of the web pages so that they display?
Thank you for your time.
For the case-changing problem, I'd be looking elsewhere if fixing this doesn't help.
Also, you can shorten that code up quite a bit by making the "www." optional:
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain1\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain2\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain3\.com [NC]
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
If you want to further reduce the size of the code, you can use the "local OR". But be aware that the solid pipe character used to indicate a local OR is modified by posting on this forum; So change the broken pipes "¦" to solid pipes before use. You should also canonicalize the new domain as "www":
RewriteCond %{HTTP_HOST} ^(www\.)?(olddomain1Šolddomain2Šolddomain3)\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^newdomain\.com [NC]
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
I couldn't get your last two suggestions to work for me. (Yes, I did replace the pipe symbol.) It seems to send the browser into a loop - I tested with IE7 and Firefox 2.0.0.2. After a while Firefox reports the following error:
"The page isn't redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
* This problem can sometimes be caused by disabling or refusing to accept cookies."
I'm not too worried though - the longer version is doing the trick. Thank you so much for your time.
That would imply one of three problems: Either a bad (or very old) POSIX regular-expressions library install on your machine, an error in transliterating the "olddomain/newdomain" strings to the actual host names, or an unneeded "correction" of the code that broke it (The code is simple, well-known, and correct as originally posted).
Because the first of these possibilities would imply a serious current problem and the potential for much trouble in the future, I'd advise checking it out...
BTW, the "Live HTTP Headers" Mozilla/Firefox extension is a great tool for testing redirects.
Jim
I do not have full admin access to the web server that I am working with. Only to the directory that contains our web site. The server belongs to and is administered by the company that hosts our web site. I will certainly be contacting them about the point you raised regarding the POSIX library.
I am sure that I got the domain names correct in the the .htaccess files I created following your suggestions above. I checked them very closely. I will be testing them again, this time using the "Live HTTP Headers" add-on you suggested. Thanks for the tip.
But it is working now. Thank you very much.
Jac
Jim, I've had another look at what I had done. You're absolutely correct I did mess it up. I "simplified" my old domain names in my original post. It would have been more accurate to list my old domain names as olddomain.com, olddomain.co.uk and olddomain.co.za, and the new domain name as olddomain.com.au. So when I modified your second suggestion above I ended up with:
RewriteCond %{HTTP_HOST} ^(www\.)?(olddomain\.comŠolddomain\.co\.ukŠolddomain\.co\.za) [NC,OR]
RewriteCond %{HTTP_HOST} ^olddomain\.com\.au [NC]
RewriteRule (.*) [olddomain.com.au...] [R=301,L]
Of course the the loop occurred because of the first argument in the first RewriteCond matched also olddomain.com.au. When I added the part to check also for a port number at the end of the condition it worked perfectly. ie (:[0-9]{1,5})?$
Thank you very much for your help.