Htaccess从url中删除目录导致页面无法打开


htaccess removing directory from url makes page not open

我在一个名为" pages "的文件夹中有一个名为about.php的页面。

我成功地从url中删除了。php和目录,但是现在页面无法打开。

我所有的文件都在localhost/test/文件夹内。所以所有东西都可以正常打开localhost/test/pages/about.php现在显示localhost/test/about,但没有打开。

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

您可以使用:

RewriteEngine On
RewriteBase /test/
RewriteCond %{THE_REQUEST} 's/+(?:index)?(.*?)'.php['s?] [NC]
RewriteRule ^ %1 [R=301,L,NE]
RewriteCond %{THE_REQUEST} /pages/ [NC]
RewriteRule ^pages/(.+)$ $1 [L,NC,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/pages%{REQUEST_URI}'.php -f [NC]
RewriteRule ^([^/]+)/?$ pages/$1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI}'.php -f [NC]
RewriteRule ^([^/]+)/?$ $1.php [L]