0

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:

http://www.mywebsite.com/docs/abcdef/?docid=abcdef

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:

http://www.mywebsite.com/index.php?docid=?docid=abcdef

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.
Omar Saad
  • 111
  • 1

1 Answers1

0

Just set the trailing / as optional with ?:

RewriteRule ^docs/(......)/?$ index.php?docid=$1 [L]
Froggiz
  • 3,043
  • 1
  • 19
  • 30