.htaccess从网址中删除index.php并隐藏参数键 [英] .htaccess remove index.php and hide parameter key from URLs
本文介绍了.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]
这篇关于.htaccess从网址中删除index.php并隐藏参数键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文