.htaccess remove index.php from subdir重定向所有动态页面
尝试从中删除index.php并解析为有效的子目录名,但是在更改.htaccess文件后,所有其他页面都重定向到子目录。.htaccess remove index.php from subdir重定向所有动态页面,php,.htaccess,Php,.htaccess,尝试从中删除index.php并解析为有效的子目录名,但是在更改.htaccess文件后,所有其他页面都重定向到子目录。 例如: 更改:site.com/subdir/index.php为site.com/subdir/但随后site.com/subdir/page?id=4解析为site.com/subdir/ .htaccess: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.p
例如:
更改:
site.com/subdir/index.php
为site.com/subdir/
但随后
site.com/subdir/page?id=4
解析为site.com/subdir/
.htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteBase /subdir/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
如何编写此规则,以便只有index.php解析为/subdir/而不是该目录中的其他页面?您可以在site root.htaccess中使用这些规则:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*/)index\.php[?\s] [NC]
RewriteRule ^ %1 [L,R=301,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ subdir/index.php [L]
它位于根目录中
/subdir/
中是否也有.htaccess?在/subdir/
中没有.htaccess文件。非常感谢你!这帮了大忙!