我正在尝试创建一个简单的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]