Forum Moderators: phranque
problem is when i check www.domain.com/index.htm i get the proper 301 redirect with location showing www.domain.com, but when I check www.domain.com/ it also shows a 301 redirect instead of the proper 200 ok.
any suggestions?
thanks
-phish
apache version is 1.3.33 if it matters
If so, it's likely you've put your server in a loop... You may find that the page load time is slower (flush your cache to test this).
If index.htm is still declared as your index page (See Apache DirectoryIndex directive), then you need to use a 'tricky' bit of code to prevent problems. It requires the use of mod_rewrite and checking a particular server variable to prevent this looping.
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.htm\ HTTP/
RewriteRule ^index\.htm$ http://www.example.com/ [R=301,L]
Note that THE_REQUEST is the entire client request header. For example:
GET /index.htm HTTP/1.1
For background information on mod_rewrite and regular expressions, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
Jim
[edit] Corrected formatting problem. [/edit]
[edited by: jdMorgan at 2:32 pm (utc) on Jan. 31, 2006]
<props>by the way i'd also like to say how much I personally appreciate the time, and dedication, you and the other mods put into this forum helping others out. It is truly appreciated, and I want you to know your hard work and effort does not go unnoticed</props>
heres how my htaccess looks
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.htm\ HTTP/
RewriteRule ^index\.htm$ [example-domain.com...] [R=301,L]
RewriteCond %{HTTP_HOST}!^www\.example-domain\.com
RewriteRule (.*) [example-domain.com...] [R=301,L]
any ideas what i broke..lol
ps...there is a hyphen in my domain..does it need to be escaped?
thanks
-phish
Be sure to flush your browser cache before testing after making *any* change to your configuration files.
Hyphens don't need to be escaped.
Jim
this is my .htaccess:
ErrorDocument 400 /400.html
ErrorDocument 403 /403.html
ErrorDocument 404 /404.html
ErrorDocument 500 /500.html
RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^ht*p://www.example.com.*$ [NC]
RewriteCond %{HTTP_REFERER}!^ht*p://www.example.net.*$ [NC]
RewriteCond %{HTTP_REFERER}!^ht*p://example.com.*$ [NC]
RewriteCond %{HTTP_REFERER}!^ht*p://example.net.*$ [NC]
RewriteCond %{HTTP_REFERER}!^ht*p://xx.xx.xx.xx.*$ [NC]
RewriteCond %{HTTP_REFERER}!^ht*p://.*\.google\..*$ [NC]
RewriteCond %{HTTP_USER_AGENT}!^Googlebot.*$
RewriteCond %{HTTP_USER_AGENT}!^Mediapartners.*$
RewriteCond %{HTTP_USER_AGENT}!^Scooter.*$
RewriteRule (\.gif)¦(\.jpg)¦(\.mpg)¦(\.wmv)¦(\.avi)¦(\.mpeg) - [F]
RewriteCond %{HTTP_HOST}!^www\.example\.com [NC]
RewriteRule ^(.*)$ ht*p://www.example.com/$1 [R=301,L]
the first is an anti-hotlinking part, the second to put www. in front
now if i request example.com/testa/testb/testc/ it seems to redirect to www.example.com/testb/testc/
anyone knows?
RewriteCond %{HTTP_HOST}!^www\.example\.com [NC]
RewriteRule ^(.*)$ ht*p://www.example.com/$1 [R=301,L]
This code appears to be auto-generated, and is far from efficient. You can accomplish the same thing with only six lines:
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.(com¦net) [NC]
RewriteCond %{HTTP_REFERER} !^http://192\.168\.10\.10/
RewriteCond %{HTTP_REFERER} !^http://([^.]+\.)*google\. [NC]
RewriteCond %{HTTP_USER_AGENT} !(Googlebot¦Mediapartners-Google¦Scooter)
RewriteRule \.(gif¦jpg¦mpe?g¦wmv¦avi)$ - [F]
Change the broken pipe "¦" characters to solid pipe characters before use; Posting on this board modifies them.
Jim
For example, if you had an .htaccess file in the directory /mystuff/widgets that said:
RewriteRule ^green_widget\.html$ /widgets.php?prod=widget&color-green [L]
RewriteRule ^/mystuff/widgets/green_widget\.html$ /mystuff/widgets/widgets.php?prod=widget&color-green [L]
Jim
RewriteCond %{HTTP_HOST}!^www\.example\.com [NC]
RewriteRule ^htdocs/(.*) http://www.example.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.(html¦htm¦shtml)\ HTTP/
RewriteRule ^htdocs(.*)/ http://www.example.com$1/ [R=301,L]
</Directory>
----------
Thanks
You could also use the pattern
/([^/]+/)*index\.s?html?\ HTTP/
instead of
/.*index\.(html¦htm¦shtml)\ HTTP/
to speed things up a bit.
Jim