Apache 使用htaccess在url中隐藏两个GET方法
我有一个网站example.com,我正在url中传递两个GET参数Apache 使用htaccess在url中隐藏两个GET方法,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,我有一个网站example.com,我正在url中传递两个GET参数 example.com/page.php?page=5§ion=10 现在我想让它显示出来 example.com/5/10 第一部分我已经准备好了,但第二部分(第二部分)我似乎还没搞清楚 我当前的.htaccess文件是 RewriteEngine on RewriteCond %{THE_REQUEST} \s/+page\.php\?page=(\d+) [NC] RewriteRule ^ /%1
example.com/page.php?page=5§ion=10
现在我想让它显示出来
example.com/5/10
第一部分我已经准备好了,但第二部分(第二部分)我似乎还没搞清楚
我当前的.htaccess文件是
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/+page\.php\?page=(\d+) [NC]
RewriteRule ^ /%1? [R=301,L,NE]
RewriteRule ^(\d+)/?$ page.php?page=$1 [L,QSA,NC]
我所需要的只是第二部分的工作(§ion=10)您可以使用这个
RewriteEngine on
#redirect and rewrite the single get perm /?page
RewriteCond %{THE_REQUEST} \s/+page\.php\?page=(\d+) [NC]
RewriteRule ^ /%1? [R=301,L,NE]
RewriteRule ^(\d+)/?$ page.php?page=$1 [L,QSA,NC]
#redirect and rewrite urls with multiple perms
RewriteCond %{THE_REQUEST} \s/+page\.php\?page=(\d+)§ion=(\d+) [NC]
RewriteRule ^ /%1/%2? [R=301,L,NE]
RewriteRule ^(\d+)/(\d+)/?$ page.php?page=$1§ion=$2 [L,QSA,NC]
将此添加到您的
.htaccess
:
RewriteEngine On
RewriteCond %{QUERY_STRING} page=(.+)§ion=(.+)$ [NC]
RewriteRule ^ /%1/%2? [R=301,L,NE]
这将使用{QUERY\u STRING}
获取变量,并将URL重写为http://example.com/5/10
。在重写结束时使用?
是为了在重写后停止将查询追加到末尾
在测试此项之前,请确保清除缓存。这项操作非常有效,但仅当我同时使用这两个参数时。但是,我想要的是单独使用第一个参数,或者同时使用第一个和第二个参数(不单独使用第二个参数),也就是说,要么使用
?page=5§ion=10
,要么使用?page=5
。现在我该怎么做?应该在主要的帖子里澄清一下。很抱歉那太好了!谢谢。我真的很感谢你的帮助:)谢谢你的回答。我真的很感激:)