开发者

mod_rewrite won't remove file extensions with other rewrite rule in place

开发者 https://www.devze.com 2023-02-13 18:40 出处:网络
I have the following mod_rewrite within my .htaccess file: RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f

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]
0

精彩评论

暂无评论...
验证码 换一张
取 消