htaccess删除除了一个特定文件夹之外的php扩展名

问题描述 投票:0回答:2

我有一个PHP项目,我需要使用.htaccess隐藏URL中的.php扩展名。我已经可以用这个.htaccess文件做到这一点

# Run Php without filename extension
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php

# Return 404 if original request is .php
RewriteCond %{THE_REQUEST} "^[^ ]* .*?\.php[? ].*$"
RewriteRule .* - [L,R=404]

现在,我需要在名为php的文件夹中的index.php中允许.php扩展名,该文件夹位于名为server(project / server / php / index.php)的文件夹中。

我怎样才能做到这一点?

php .htaccess
2个回答
0
投票

将以下行添加到.htaccess文件中。

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

有关详细信息,请通过以下链接。

https://www.plothost.com/kb/how-to-remove-php-html-extensions-with-htaccess/


0
投票

尝试以下规则,

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^(.*)$ $1.php [L]
© www.soinside.com 2019 - 2024. All rights reserved.