Rewrite regular regex redirection to base file

I am trying to do a simple cheat on the mod_rewrite url where /category/item rewrites /category/index.php?id=item . In the /category directory, I have this in my .htaccess file:

 Options +FollowSymLinks RewriteEngine on RewriteBase /category/ RewriteRule ^(.+)$ index.php?id=$1 [L] 

It sends the request to the index.php script just fine, but instead of searching for β€œitem” in the id variable, I get β€œindex.php”. That is, /category/item seems to be rewritten to /category/index.php?id=index.php .

I tried endless variations, with different / no RewriteBase and other changes, but nothing works. Any idea where I was wrong?

+4
source share
1 answer

The problem is that the index.php file is in the same directory as htaccess, and is included and is being processed by rewriting. Try adding rewriting conditions:

 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d 

In addition, the input you pass to id paramater is very insecure. Assuming you are using numeric identifiers, you can use [0-9] instead . to ensure that only numbers are transmitted. If they are alphanumeric, you still want to use something like: [a-zA-Z0-9\-_] .

+3
source

Source: https://habr.com/ru/post/1313992/


All Articles