Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess remove index.php from subdir重定向所有动态页面_Php_.htaccess - Fatal编程技术网

.htaccess remove index.php from subdir重定向所有动态页面

.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

尝试从中删除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.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文件。非常感谢你!这帮了大忙!