Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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 mod_rewrite将所有请求重定向到index.php,包括目录_.htaccess_Url_Mod Rewrite_Url Rewriting_Rewrite - Fatal编程技术网

.htaccess mod_rewrite将所有请求重定向到index.php,包括目录

.htaccess mod_rewrite将所有请求重定向到index.php,包括目录,.htaccess,url,mod-rewrite,url-rewriting,rewrite,.htaccess,Url,Mod Rewrite,Url Rewriting,Rewrite,我想将所有请求重定向到index.php 例如:localhost/abc/def-->localhost/index.php?url=abc/def 这是我的.htaccess线路: RewriteRule ^(.*)$ index.php?url=$1 [QSA,L] 但我有一个问题,我有一个目录“test”,当我转到localhost/test时,我希望它重定向到locahost/index.php?url=test,但地址栏显示的是localhost/test/?url=test 如何

我想将所有请求重定向到index.php

例如:
localhost/abc/def
-->
localhost/index.php?url=abc/def

这是我的.htaccess线路:

RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
但我有一个问题,我有一个目录“test”,当我转到
localhost/test
时,我希望它重定向到
locahost/index.php?url=test
,但地址栏显示的是
localhost/test/?url=test


如何删除查询字符串?(
?url=test
或类似的东西,当我输入访问目录的地址时)?

这是因为
mod_dir
在重写规则之后运行,并添加重定向以添加尾部斜杠

您可以在根目录中使用此选项。htaccess:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?)/?$ index.php?url=$1 [QSA,L]

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+?)/$ index.php?url=$1 [QSA,L]

你试过吗?+1!我想知道为什么它似乎同时进行重写和重定向!