Forum Moderators: phranque
All other pages are normally redirected to www.domain.com correctly.
This presents duplicate page problems, right?
The SERPS show the home page as non-www; with all other pages correctly in www format.
So I've corrected the htaccess file to now read
Redirect permanent /index.html [domain.com...]
I suspect I need to do more, right?
Back in a prior thread (http://www.webmasterworld.com/apache/3009363.htm)
this looks to be the thing that will both resolve the www - non-www redirection, and redirect calls to index.html back to the root.
RewriteEngine on
RewriteCond %{HTTP_HOST}!^www\.example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . http://www.example.com%1/%2 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*)index\.html\ HTTP/
RewriteRule index\.html$ http://www.example.com/%1 [R=301,L]\
Am I headed somewhat in the right direction here?
Patching this into my .htaccess file causes some things to work, others not.
RewriteEngine on
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*)index\.html\ HTTP/
RewriteRule index\.html$ http://www.example.com/%1 [R=301,L]
#
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . http://www.example.com%1/%2 [R=301,L]
#
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
Jim
[edited by: jdMorgan at 2:26 am (utc) on June 22, 2008]
Remove it and all is well.
Keep in mind there are about a dozen permanent redirects that remain in the htaccess file below the "rewrite" stuff.
I'll try a few things more - but what are some of the general ways to go about troubleshooting this?
Troublshooting:
1) Comment-out lines or sections by prefixing a "#" to the lines to isolate problems.
2) If you get a 500-Server Error, then look at your server error log file -- It will often tell you exactly what is wrong.
If you still need help after that, then please post the entire set of rewrites and redirects -- mod_alias and mod_rewrite both.
Jim
[edited by: jdMorgan at 2:26 am (utc) on June 22, 2008]
here's the many times repeated line from the server error log:
/var/www/html/.htaccess: RewriteRule: bad flag delimiters
In case it hasn't already become clear, the directive-line parsers in mod_rewrite (and other Apache modules) are written to be simple and therefore very fast. As a result, they are absolutely unforgiving of syntax errors, and can be cryptic in their complaints. :)
Jim
The removal of the trailing / of the last line in the first post did in fact resolve the "bad flag delimiter" error.
Typing in the non-www url, does indeed return the www.example.com as it now should (and never did before) so that is good progress.
What I still think I misunderstand (or may have miscommunicated) is the whole idea of trying to get the index.htm page to NOT show up in the url (thus avoiding duplicate page problems).
Like when I type in amazon.com, it loads amazon.com/, not visually redirecting to an index.htm page.
Virtually all of my inbound links are to the www.example.com/ not the index.htm page, so when I type in www.example.com, shouldn't this return www.example.com/ and not www.example.com/index.htm?
perhaps there is something else going on?
Without these 2 lines, it loads a 404 when I try to view the root or the index.html page (but of course, index.htm works fine)
Redirect permanent /index.html http://www.example.com/index.htm
Redirect permanent /index.php http://www.example.com/index.htm
thanks,
-C
Remove them and replace with
DirectoryIndex index.htm
See Apache mod_dir for more info.
Then change the first rule I recently posted above to:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.(html?¦php)\ HTTP/
RewriteRule ^(([^/]+/)*)index\.(html?¦php)$ http://www.example.com/$1 [R=301,L]
Jim
Just now I learned about rex swain's http viewer and double checked to see if the www and non-www were rendering correctly.
www renders a 200
non-www renders a 301
-
when I remove the .htaccess code, both render a 200 code.
do I understand now that I don't need the non-www to www redirect?
if that is correct, is there any damage done by leaving it as it is?
-C
A 200 for www and a 301 for non-www is the correct server response scenario. See Hypertext Transfer Protocol -- HTTP/1.1 [w3.org]
You may also want to consider using the "Live HTTP Headers" add-on for Firefox/Mozilla browsers, since it's more convenient than using a third-party site.
Jim
of course - another question arises...
I find many sites where this appears to be needed.
In a weeks time, there have been no noticeable changes on this current site, although ranking seems slightly better but that's hard to pin down - but I anticipate, if there are any changes at all, they may take a bit longer.
With a site that has about a dozen pages and about 300 backlinks, what do you guess (or experience) might be normal in terms of traffic increases?
Also, while search results are returned instantly, every thing else takes days, weeks, or months. Wait 30 days before checking again, and check again 60 days after than... Only very-high-PageRank sites see change within days.
Jim
Thanks for the reminder - it caused me to see where I had missed a couple of pages.
(If only other tools were so simple and complete)
Feel free to suggest anything else I shouldn't leave out!
I've used Xenu and recommended it for years - I forget where I first heard of it but I wouldn't be surprised if it was here!
I expect to be using this htaccess file again and again!
I just hope I can see a difference in my stats as I don't want to suggest / recommend it without being able to know personally about what it can do.
However, after a few page views, FireFox and IE both indicate the page cannot load. It is as if it works fine and then stops working over the space of about 1 minute.
FF generates the following error message:
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.
===
This is on a v-host which means I don't have access to logfiles.
Pls advise what are best next steps for troubleshooting.
-C
PS .htaccess in discussion is:
RewriteEngine on
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.(html?¦php)\ HTTP/
RewriteRule index\.html$ http://www.example.com/%1 [R=301,L]
#
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . http://www.example.com%1/%2 [R=301,L]
#
RewriteCond %{HTTP_HOST} !^www\.example.com\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
DirectoryIndex index.html
Also, if this redirection loop is visible to and reported by Firefox, install the "Live HTTP Headers" add-on -- It gives a much more detailed HTTP Headers view, and the first two redirect responses it logs when your rules are looping will probably clearly illustrate what is going on.
Jim