.htaccess url重写后,系统添加扩展名
使用my.htaccess中的以下规则,系统会在我的url末尾添加一个.htaccess url重写后,系统添加扩展名,.htaccess,.htaccess,使用my.htaccess中的以下规则,系统会在我的url末尾添加一个.php RewriteEngine On # Removing extension RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.php [NC,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^app/([^/]+)$
.php
RewriteEngine On
# Removing extension
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^app/([^/]+)$ app.php?module=$1 [L]
为什么?
谢谢。只有在检查
.php
文件是否存在后,才让您的第一条规则添加.php
:
RewriteEngine On
# add extension
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^.]+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^app/([^/]+)$ app.php?module=$1 [L,QSA,NC]
只有在检查
.php
文件是否存在后,才让您的第一条规则添加.php
:
RewriteEngine On
# add extension
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^.]+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^app/([^/]+)$ app.php?module=$1 [L,QSA,NC]