从url中删除.php-仅重写子页面
我正在尝试从一个我已经开始工作的站点中删除.php扩展从url中删除.php-仅重写子页面,php,apache,.htaccess,url,Php,Apache,.htaccess,Url,我正在尝试从一个我已经开始工作的站点中删除.php扩展example.com/parent/child.php正确更改为example.com/parent/child/ 但是,当转到example.com/parent.php时,它仍然会正确重写,但会显示一个索引页 我是.htaccess和Apache的新手,因此非常感谢您的帮助 根据评论进行更新 “很抱歉,它不允许我写代码。我从这篇文章中抓到了它: " 好吧,如果你不发布你的重写规则,我们就无能为力……对不起,这不允许我写代码。我从这篇博文
example.com/parent/child.php
正确更改为example.com/parent/child/
但是,当转到example.com/parent.php
时,它仍然会正确重写,但会显示一个索引页
我是.htaccess
和Apache的新手,因此非常感谢您的帮助
根据评论进行更新
“很抱歉,它不允许我写代码。我从这篇文章中抓到了它: "
好吧,如果你不发布你的重写规则,我们就无能为力……对不起,这不允许我写代码。我从这篇博文中抓到了它:来自Bhavana的博文。你复制并粘贴了多个代码吗?没有,我只是使用了如上所示的代码。
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]