Forum Moderators: phranque
Can anyone tell me what's wrong here:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteRule ^5201\.html$ http://www.example.com/ [R=301,L]
Please give us an example of what URL "doesn't work," what URL you requested, what you expected, what actual result you got, and how the expected and actual results differ. While it may seem obvious to you, it's especially important to be very, very clear when "odd" results such as this are encountered.
Where is this code located, in .htaccess or in a server config file?
Do you have any other rules in this file or in others that may be interacting with these rules to produce unexpected results?
Do you have any scripts that generate redirects?
Jim
I'm working with an htaccess file. All other features in the htaccess file are working like:
ErrorDocument 404 /missing.html
AddHandler server-parsed .html
I moved the rewrite rule for home page to just after RewriteEngine on and that works fine.
However, I have other pages I'm redirecting also and when I moved that command below the one mentioned above and removed the www. from browser and entered the old url, and clicked in browser window the rewrite rule just brings up the old page. IF I click on it a 2nd time then it redirects properly to the new page with the www showing.
This one is in a folder so maybe I didn't write it correctly:
RewriteRule ^5441/index\.html$ http://www.example.com/example.html [R=301,L]
The error code, parser code and 301 for www for home pg works fine.
Are you saying the redirects to home page (cannonical and new home page location) should be written as one command? If so I'm not sure how to write it.
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^5201\.html$ http://www.example.com/ [R=301,L]
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
No. I am saying that you should have one rule that fixes a "page" but that for the "page" it should force "http" and "www" at the same time.
After that you might have another rule that fixes some other "page" and that for that "page" it should force "http" and "www" at the same time.
Finally, you will have a rule that fixes all non-www requests and forces "http" and "www". This rule never runs for the above-mentioned pages because previous rules have already fixed them.
So, for any particular request, only one rule runs. If the rules were in some different order, multiple rules would run, one to change to www and another to strip the filename. You must avoid this redirection chain.