我经历过许多类似的问题,但我找不到这个特殊的案例:
具有这种结构的:
public_html/
q/
.htaccess
index.php
/dirnofixedname1
/dirnofixedname2
/dirnofixedname3
这样做的目的是处理请求,比如:http://domain/q/dirnofixedname2
和http://domain/q/index.php?q=dirnofixedname2
,同时仍然显示http://domain/q/dirnofixedname2
。一个很受欢迎而且已经解决的案子。
因此,.htaccess文件是:
RewriteEngine On
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ index.php?q=$1 [L]
问题是,当请求与现有目录(我想要的)匹配时,它按预期工作(index.php
执行并获得q
),但重定向到:
http://domain/q/dirnofixedname2/?q=dirnofixedname2
(并在URL栏中显示这一点),而不是预定的:
http://domain/q/dirnofixedname2
特别是,如果目录碰巧不存在,
http://domain/q/dirthatdoesnotexist
由index.php
以q
作为dirthatdoesnotexist
正确处理(脚本显然不接受该处理,而不返回任何内容)。
对于在子Do存在的情况下如何避免重定向,您有什么想法吗?(与参数具有相同的dir名称是实用的)
发布于 2019-04-14 22:19:41
这是由于DirectorySlash
指令(默认情况下为On
状态)发生的,因为您在URI中请求一个实际的目录。
您可以通过以下方式关闭它:
DirectorySlash Off
此外,要屏蔽目录清单,请使用:
Options -Indexes
在你的.htaccess顶部
https://stackoverflow.com/questions/55479697
复制相似问题