mod_rewrite won't remove file extensions with other rewrite rule in place
I have the following mod_rewrite within my .htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9a-zA-Z]+)$ index.php?ID=$1 [QSA,NC,L,R]
The code above works but the issue is several of the pages on my site link to files without extensions because our original .htaccess file removed all extensions from every request. My site is bui开发者_Python百科lt on PHP. Ultimately I want to use the rules above exactly as is but at the end of it all, i want to strip the file extension (.php) from every request.
Is this possible?
Try this
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !^index.php
RewriteRule ^(.*)\.php$ $1 [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9a-zA-Z]+)$ index.php?ID=$1 [QSA,NC,L,R]
精彩评论