Reputation: 787
I have the following URL structure:
http://example.com/file.php?section=sectionName
I would like to convert this to:
http://example.com/file/sectionName
Current attempt appears not to work:
RewriteRule ^(.*)$ file.php?section=$1 [L,QSA]
and appears to interfere with another rewrite which is stripping .php
endings from filenames:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [L]
Upvotes: 1
Views: 32
Reputation: 41219
You can use this htaccess :
RewriteEngine On
#rewrite /file => file.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ $1.php [L]
#rewrite /file/foobar => file.php?section=foobar
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^file/([^/]+)/?$ /file.php?section=$1 [NC,L]
Upvotes: 1