Ad

"RewriteRule ^([^/]+) Index.php?id=$1" Posts "index" Instead Entered Text

- 1 answer

If I do it by typing /?id=some_text in url then index.php script works as it shuld but if I do /some_text then index.php always receives id to have value "index".

At first I had RewriteRule ^([^/]+) ?id=$1 but that returned "Internal Server Error" instead web page, then I changed it to RewriteRule ^([a-z]+) index.php?id=$1 and I stoped reciving error page but script started to receive "index" as value no matter what i typed in

This rule worked on local machine using MAMP, but when I uploaded it on server it stoped working.

.htaccess file for this folder only contains this rule

RewriteEngine on
RewriteRule ^([^/]+) ?id=$1
Ad

Answer

I believe it was probably trying to recurse through index.php since it appears to match the rule.

Try:

RewriteEngine On
RewriteCond  %{REQUEST_URI}  !index
RewriteRule ^([^/]+) index.php?id=$1 [L]

The RewriteCond is to ensure it doesn't apply the rule to the results of itself. And [L] is to make sure it doesn't try applying any other rule.

Ad
source: stackoverflow.com
Ad