Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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:

http://hydesim.com?dll=40.71427,-74.00597&yd=10&zm=12&op=156

…becomes this:

http://meyerweb.com/eric/tools/gmap/hydesim.html/?dll=40.71427,-74.00597&yd=10&zm=12&op=156

…instead of this:

http://meyerweb.com/eric/tools/gmap/hydesim.html?dll=40.71427,-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
3  
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

2 Answers 2

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 meyerweb.com/… . (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

 
discard

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.