1

How can I hide the file's extension and the GET variables via .htaccess in one line?

This code doesn't work:

...
RewriteRule ^(.*)$ $1.php [L]
RewriteRule ^file-([0-9]+)\.php$ /some_directory/files.php?id=$1 [L]

Example:

http://www.example.com/file.php?variable=value

Should be:

http://www.example.com/file

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Zhafur
  • 1,626
  • 1
  • 13
  • 31
  • Please edit your question to give some examples of the URL you input and the result you expect. – Alex W Jul 26 '12 at 17:31

2 Answers2

2

You need to add a few conditions to the first rule to keep it from looping, you can try changing it to:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]

Then go continue with your second rule, which loks fine the way it is.

Jon Lin
  • 142,182
  • 29
  • 220
  • 220
0

This is a better for static pages. You only need to change "index" as your file and change get element according to yours. In example, there is "id" element.

RewriteEngine On
RewriteRule ^((?:[a-zA-Z0-9_-]|%20)+)/?$ index.php?id=$1
can
  • 33
  • 6