htaccess在没有扩展名的情况下破坏网址

时间:2017-08-17 10:22:24

标签: apache .htaccess mod-rewrite

我在我的.htaccess中使用此功能从网址中删除.php:

Options +FollowSymLinks -MultiViews  
RewriteEngine On  
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteRule ^([^\.]+)$ $1.php [NC,L]  

问题是我的网址如下:

/services/marketing.php(没有扩展名正确显示 - / services / marketing)

/services(当我将规则放入时会中断。这是一个默认情况下提供其中包含的index.php的目录)

任何人都知道如何编写.htaccess规则,以便它们允许这两种风格的URL工作吗?

1 个答案:

答案 0 :(得分:0)

@CBroe分享的链接回答了这个问题 - Mod_rewrite check if php file exists

我遗失的那条线是:

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}\.php -f
相关问题