Forum Moderators: phranque

Message Too Old, No Replies

Ensure Trailing Slashes w/Querystring

Using mod_rewrite to add trailing slashes on Drupal URLs

         

MikeSchinkel

6:00 am on Jul 30, 2007 (gmt 0)

10+ Year Member



Hi all:

I'm running Drupal 5.1 and it uses URLs in the form of:

http://example.com/foo

I want to use trailing slashes such as:

http://example.com/foo/

so I used the following to 301 redirect the former to the latter:

#Ensure Trailing Slashes
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ [%{HTTP_HOST}...] [R=301,L]

However, the problem comes in when there is a query string as follows such as is required during login:

http://example.com/foo?var=value

I've tried many things but can't see to get the site to work correctly with the above in my .htaccess file. Can anyone help me make this work?

Thanks in advance.

j_a_c_k

2:23 pm on Jul 31, 2007 (gmt 0)

10+ Year Member



Mike,
I had a related problem and this advise helped.
[webmasterworld.com...]

Note that you can reattach the origional query string (if any).

jdMorgan

3:13 pm on Jul 31, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The code, as posted, has no effect on query strings. They will be passed through unchanged, whether the redirect is invoked or not.

The pattern for detecting URL-paths containing "." or ending in "/" has a flaw: It will not append a slash if the root page of the site is requested as, for example, "example.com". However, it is possible that mod_dir will be invoked to correct this situation.

We need a better description of what you mean by "it doesn't work."

What URLs are you requesting?
What results do you expect for each?
How do actual results differ from your expectations?

Jim