1

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.

anubhava
  • 761,203
  • 64
  • 569
  • 643

2 Answers2

0

Try this rule:

RewriteRule ^view\.doc\.(.+)$ index.php?doc=$1 [L,QSA,NE,NC]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • yes but it seems that the 404 problem persisted only because the script was working from a sub directory. i simply added the html tag to the document header and your rewrite solution worked quite well. – user3010407 Dec 19 '13 at 12:52
0

I propose a slightly different solution from the @anubhava's one, by prepending a slash before index.php, tested on Debian/Apache2:

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

It gives:

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

I cannot test anti-slash \, as no browser permits me to test this in URL without transforming it to slash /.

jacouh
  • 8,473
  • 5
  • 32
  • 43