0

I have been developing a shop, which uses mod_rewrite to allow us to make the URIs more readable, for instance:

http://www.example.com/shop/Tools

Will be rewritten to

http://www.example.com/index.php?area=shop&folder=Tools

My rewrite rule is as follows:

RewriteRule ^shop/([^?#]+) index.php?area=shop&folder=$1 [NC,QSA,L]

However, this breaks when the folder name ends in . (dot), as I discovered when testing with a folder name ending in "etc."

It seems any trailing dots are totally removed before $_GET has been populated. If I put another character after the dot, it's fine, if the URI ends in any number of dots, they are removed

Is there a way to stop this from happening?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Pez
  • 172
  • 2
  • 15
  • 1
    Doh, been searching for ages and didn't find these, http://stackoverflow.com/questions/16383339/mod-rewrite-with-trailing-period-in-url http://stackoverflow.com/questions/11144079/apache-mod-rewrite-ending-periods – Pez Mar 06 '14 at 10:29
  • Actually, a little more digging and testing has revealed that this is a Windows only problem, if anyone could shed any light on this I'd appreciate it – Pez Mar 06 '14 at 10:34

1 Answers1

0

You don't need to exclude "?" and "#" in RewriteRule since it operates only on URI (path), without query-string or anchor.

So, this is enough:

RewriteRule ^shop/(.+) index.php?area=shop&folder=$1 [NC,QSA,L]

That being said, this does not change the fact that dots get stripped.

This may be a result of MultiViews being on. This option makes Apache try and resolve the URIs disregarding extensions.

So, add this as well:

Options -Multiviews
poncha
  • 7,726
  • 2
  • 34
  • 38
  • Thanks Poncha, that didn't help though – Pez Mar 06 '14 at 12:19
  • Apparently it's a Windows issue (it works fine on my linux server) – Pez Mar 06 '14 at 12:19
  • Well, you can use the solution provided in one of the links you've found and parse the `REDIRECT_URI` (inside php) afterwards to overcome this issue. That is if you care about it running on windows ;) – poncha Mar 06 '14 at 12:21
  • Not in this particular instance but it'd still be nice to know :) REDIRECT_URI isn't available on my machine, will look into it more – Pez Mar 06 '14 at 12:24