Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have some domain redirects that point to a page on my server, and they stick a trailing slash after the filename but before the query string. So this:,-74.00597&yd=10&zm=12&op=156

…becomes this:,-74.00597&yd=10&zm=12&op=156

…instead of this:,-74.00597&yd=10&zm=12&op=156

So how do I drop that middle-of-URL slash while preserving the query string? I’ve tried some .htaccess approaches but nothing seems to work. The most recent attempt was:

RewriteRule ^(.+)html/(.+)$ /$1html$2 [R=301,L]

[UPDATE: That rule didn’t work, so I disabled it, and now there are no rewrites in effect.] I’m not very experienced with mod_rewrite, as you might have guessed. Any help greatly appreciated!

share|improve this question
That rewrite rule doesn't match the URL you posted. Please post the actual rewrite rules being used. – Michael Hampton Feb 13 '13 at 4:42
I’m not using any rewrite rules right now, as I disabled that one after it didn’t work, and there are no others (except for the domain redirect at the registrar, which appears to be where the slash comes from). – Eric A. Meyer Feb 13 '13 at 15:45
up vote 3 down vote accepted

Apache's mod_rewrite does not match the query string in its RewriteRules. You don't even need QSA if you are not redirecting to a URL with a query string specified. I tested this locally on Apache 2.2.22 (OS X Lion's native version) and it worked.

RewriteRule ^(.+)html/$ /$1html [R=301,L]

EDIT: If you're putting the .htaccess in the gmap directory, you'll have to use the following in it:

RewriteEngine On
RewriteBase /eric/tools/gmap/
RewriteRule ^(.+)html/$ $1html [R=301,L]
share|improve this answer
Weird: that resolved to… . (Still does, as I write this.) – Eric A. Meyer Feb 13 '13 at 16:15
Is your .htaccess in the gmap directory? – Steven Merrill Feb 13 '13 at 16:16
Yes, it is. Currently the only rule in that file is the one you posted. – Eric A. Meyer Feb 13 '13 at 16:18
Check the updated answer for a fix. – Steven Merrill Feb 13 '13 at 16:21
Ah, of course. Perfect—thank you! – Eric A. Meyer Feb 13 '13 at 16:22

Use the QSA ("Query String Append") flag instead of trying to parse it out yourself. Something like:

RewriteRule ^(.+)html/(.+)$ /$1html [R=301,L,QSA]

share|improve this answer
Hm, doesn’t seem to work. Here’s my .htaccess: RewriteEngine On RewriteRule ^(.+)html/(.+)$ /$1html [R=301,L,QSA] The slash still doesn’t get dropped. – Eric A. Meyer Feb 13 '13 at 16:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.