Reputation: 225
I have a site using Apache rewrite module. The problem is that I'm using the RewriteRule like this:
RewriteRule ^([^/]+)/?$ /index.php?p1=$1 [L]
I need to match all the characters except "/", but it doesn't work. It counter an error "The requested URL was not found on this server."
it work with this rule:
RewriteRule ^([^/\.]+)/?$ /index.php?p1=$1 [L]
but this rule will not match the "dot", so whenever the url have the "dot" it will counter the same as above.
Please help
Upvotes: 1
Views: 347
Reputation: 143906
RewriteRule ^([^/]+)/?$ /index.php?p1=$1 [L]
The reason that isn't working is because there is an internal redirect loop, let's say you are getting a request /zoo
:
zoo
(no leading slash here) matches ^([^/]+)/?$
and the url gets rewritten to /index.php?p1=zoo
zoo
and /index.php
are different so it gets internally redirected, and the rules are applied again, leading slash strippedindex.php
matches ^([^/]+)/?$
, gets rewritten to /index.php?p1=index.php
index.php
and /index.php
are different, so internal redirect againOne way you can stop the loop is to change the rule to:
RewriteRule ^([^/]+)/?$ index.php?p1=$1 [L]
So that index.php
would match index.php
(no leading slash), but a better way would be to add some rewrite conditions:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
In front of the rewrite rule.
Upvotes: 1