.htaccess mod_rewrite将所有请求重定向到index.php,包括目录
我想将所有请求重定向到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 如何
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!我想知道为什么它似乎同时进行重写和重定向!