0

我正在尝试从我已经开始工作的站点中删除 .php 扩展名。 example.com/parent/child.php正确更改为example.com/parent/child/

但是,当转到它时,example.com/parent.php它仍然会正确重写,但会显示一个索引页面。

我对.htaccessApache 还很陌生,所以任何帮助都将不胜感激!

从评论更新

“我很抱歉,它不让我写代码。我从这篇文章中抓住了它:

删除友好 URL 的 .php 扩展名(显式编写)

RewriteEngine On
RewriteBase /

# remove enter code here.php; use THE_REQUEST to prevent infinite loops
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]


# remove index
RewriteRule (.*)/index$ $1/ [R=301]

# remove slash if not directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]

# add .php to access file, but don't redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
4

0 回答 0