Search code examples
regexapache.htaccessmod-rewritetrailing-slash

Trouble with mod rewrite and slashes and $_GET


I'm trying to implement nicer urls using mod rewrite to a php script I wrote to view documents pulled from a mysql database by their entry name. i use the following code and it works fine.

RewriteRule ^view.doc.(.+)  index.php?doc=$1

so basically

view.doc.xyz whould be index.php?doc=xyz

But im having trouble with entry names with '/' and '\' in them being viewed through the rewritten link.

view.doc.abc/123 into index.php?doc=abc/123

or like

view.doc.sg1\123 into index.php?doc=sg1\123

Ether i'd get an endless loop or get a 404 error. I'm pretty new to mod rewrite and Id very much appreciate any help on the matter.


Solution

  • Try this rule:

    RewriteRule ^view\.doc\.(.+)$ index.php?doc=$1 [L,QSA,NE,NC]