重写索引.php为无,重写为其他.php重写为其他



我正在尝试创建一个简单的CMS。
我需要.htaccess重写指向/index.php的链接,而指向/
而所有其他/files.php指向/files

目前,我正在使用类似的东西

RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /([^ ]+).php
RewriteRule ^/?(.*).php$ /$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^/?(.*)$ /$1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

这是在URL面板中重写<a href='layout/header.php'>/header,这很好。但是导航回/index.php会导致/index.php,这很糟糕。

我在这里错过了什么?

这解决了我的问题

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^GET.*index.php [NC]
RewriteRule (.*?)index.php/*(.*) /$1$2 [R=301,NE,L]
RewriteCond %{THE_REQUEST} ^GET.*index [NC]
RewriteRule (.*?)index.php/*(.*) /$1$2 [R=301,NE,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /([^ ]+).php
RewriteRule ^/?(.*).php$ /$1 [L,R=301]

最新更新