0

I want to rewrite URL with help of ".htaccess" file, but having some problem.

http://domian.in/code.php?code=hby5

to

http://domian.in/hby5

I used this below htaccess code but having "500 Internal Server Error".

RewriteEngine On
RewriteRule ^([^/]*)$ /code.php?code=$1 [L]

Any help will be appreciable.

Rahul Mukati
  • 744
  • 2
  • 10
  • 15
  • Switch on the debug mode of apache. So you can see if your rewirting works: http://stackoverflow.com/questions/7738170/how-to-debug-htaccess-rewrite-script – Jens Jul 10 '16 at 11:08

1 Answers1

0

Your rule is causing an infinite internal redirection ( /code.php => /code.php.... ) because ([^/]*) also matches your rewrite destination /code.php and rewrites it to itself , to fix this ,you need to exclude the target /code.php from the rule

RewriteEngine On
RewriteRule ^((?!code\.php)[^/]*)$ /code.php?code=$1 [L]
Amit Verma
  • 40,709
  • 21
  • 93
  • 115