.htaccess从网址中删除index.php并隐藏参数键
问题描述:
我有以下URL
www.example.com/index.php?tag= xxx
我想使用.htaccess使其类似于以下内容
I want to make it like the following using .htaccess
www.example.com/xxx
我是这样做的代码:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+?)/?$ /index.php?tag=$1 [L,QSA]
所以,如果我输入以下网址:
SO if I input this URL:
www.example.com/index.php?tag=1000
它将重定向到:
www.example.com/?tag=1000
如果: www.example.com/1000
可行!
所以我有双重网址,
如何重定向 www.example.com/index.php?tag=1000
到 www.example.com/1000
答
如何将
www.example.com/index.php?tag=1000
重定向到www.example.com/1000
您可以在 RewriteBase
行下面插入此规则:
You can insert this rule just below RewriteBase
line:
RewriteCond %{THE_REQUEST} /(?:index\.php)?\?tag=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L,NE]