Forum Moderators: phranque

Message Too Old, No Replies

site.com to site.com/

non-slash to slash

         

monia

10:45 pm on Sep 12, 2010 (gmt 0)

10+ Year Member



Hi folks. I've got a problem. Need your help a lot !

I just wanna 301-redirect root directory site.com to site.com/. After redirection it should have folloving server headers:

site.com - 301 redirected to site.com/
site.com/ - 200

To make this happened I used folloving .htacces code:
RewriteCond %{HTTP_HOST} ^site\.com$
RewriteRule ^(.*)$ http://site.com/$1 [L,R=301]

and get folloving server headers:

site.com - 301 redirected to site.com/
site.com/ - 301 redirected to site.com/

and infinite loops redirection.

What I did wrong ? why my site.com/ redirects to itself ? How can I make redirection with desired server headers ?

jdMorgan

4:22 pm on Sep 13, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The slash is not part of the hostname (HTTP_HOST), it is part of the URL-path (REQUEST_URI). Therefore, your rule will always execute, regardless of the requested URL-path.

But this missing-slash case should already be handled by Apache mod_dir. You should look into why that is not already happening (ask your host if you're renting a server). It is possible (but not likely) that mod_dir is not loaded. It is also possible (if you are on Apache 2.x) that DirectorySlash is disabled.

You could try:

DirectorySlash on

if that is the case.

I suggest that you fix this configuration problem instead of adding a redirect rule to fix it.

Jim

monia

8:27 pm on Sep 13, 2010 (gmt 0)

10+ Year Member



Its not about trailing slash for derictories. What I actually want to get are folloving server headers:

site.com - 301 redirected to site.com/
site.com/ - 200

and I dont know how to make this happend. Anybody help, pls !

jdMorgan

9:57 pm on Sep 13, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I do know how to make that happen. But you did not understand or test my answer, apparently.

Please read the mod_dir and DirectorySlash documentation at apache.org if you do not wish to test the proposed solution.

Jim