Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule: foo.com/directory --> foo.com/directory/

got an error page

         

guarriman

10:19 pm on Feb 4, 2008 (gmt 0)

10+ Year Member



Hi.

Using Apache 2, I want to create a RewriteRule within the '.htaccess' file which redirects from:
[foo.com...]
to
[foo.com...]

This last "directory" is a RewriteRule:
----------
RewriteRule ^([^/]+)/$ /directory.php?label=$1 [L]
---------

I tried adding this line
---------
RewriteRule ^(.*)$ /$1/ [R=301]
---------
after and before the last line, but I get this error message:
------
The page isn't redirecting properly
------

and the URL I get is:
[foo.com...]

What am I doing wrong? Thank you very much.

jdMorgan

12:38 am on Feb 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



added

RewriteRule ^(.*)$ /$1/ [R=301]

after and before the last line, but I get this error message: The page isn't redirecting properly

Your add-a-slash rule pattern matches any URL-path requested from your server, and generates a redirect to add a slash. So the client requests the new URL-path, now with a slash. This new URL now matches the pattern for the second rule, so the URL-path is changed to directory.php with a query string value of label=original-URL-path. Now there is no trailing slash, so the first rule is applied again, generating a redirect to directory.php/?label=original-URL-path, which is then requested by the client. Now the second rule is applied again, rewriting that URl to directory.php?label=directory.php

This then continues until either the client or the server reaches its maximum redirection limit. You can easily see this using the "Live HTTP Headers" add-on for Firefox/Mozilla browsers.

The pattern in your redirect rule must be made more specific, so that only the URL-paths you want to add a slash to will be redirected. Since I don't know all of your URLs, I can't suggest anything, except that you probably don't want to redirect any URL that already has a trailing slash, and you may not want to redirect any URL that has a period in the final URL-path-part, or exists as a 'real' file, etc.

Jim