I am trying to create a RewriteRule, but it's unreliable and I can't figure out what is happening. Here's my rule:

RewriteRule ^docs/(......)/$ index.php?docid=$1 [L]

the problem is leading slashes, which I have heard is a troublesome thing. What is happening is as follows;

if you include a slash at the end of the url, everything works as expected. however if you don't include the slash at the end, the url turns into this:


It includes the GET data after the url. The funny thing is, the website still works as expected. How does this even happen? according to the rewriterule I made, the url should be look like the following interally:


but after further testing it seems it looks like the added get data is completely ignored. seriously, I tried writing anything after the question mark. Nothing affects the website.

I would appreciate it if someone could explain to me what is happening. Also if someone could show me how to change the rewriterule for the rewrite to work.

Technical details:

  • apache-2.2 on debian
  • rewriterule written in apache config file.
  • no other rewriterules omitted.
  • Can you clarify what you mean by "the url turns into this"? The client gets redirected to that URL, correct? – Shane Madden Oct 18 '15 at 17:13

Just set the trailing / as optional with ?:

RewriteRule ^docs/(......)/?$ index.php?docid=$1 [L]
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.