1

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!

  • 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 04: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 Answers2

3

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]
0

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

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

Dave Ross
  • 101
  • 1
  • 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