mod_rewrite的:从URL删除查询字符串? [英] mod_rewrite: remove query string from URL?
本文介绍了mod_rewrite的:从URL删除查询字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用的.htaccess做出以下重定向(301)
I'm trying to make the following redirection (301) using .htaccess
*?页= 1重定向到*
*?page=1 redirects to *
(其中*是通配符)。
基本上,我只是想prevent人呢?页= 1的URL的末尾访问一个网页,而是引导他们到相同的URL减去?页= 1
。
Basically, I just want to prevent anyone accessing a page with ?page=1 at the end of the URL, and instead direct them to the same url minus ?page=1
.
是否有这样做的快捷方式?
Is there a quick way of doing this?
推荐答案
这应该做到这一点:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^page=1$
RewriteRule (.*) $1? [R=permanent]
逐行:
- 您打开重写功能。
- 您指定一个条件(if语句)的查询字符串必须准确地
页= 1
的适用以下规则。 - 然后你指定一个规则说代替整个路径(。*)与本身($ 1),但要查询字符串为空(?),使结果的永久重定向(301)。
- You turn on the rewriting functionality.
- You specify as a condition ("if statement") that the query string has to be exactly
page=1
for the following rules to apply. - Then you specify a rule that says substitute the entire path (.*) with itself ($1), but make the query string empty (?), and make the result a permanent redirect (301).
如果你想重定向是临时的(302),那么你可以删除 =永久
部分。临时移动是默认的研究
标记。
If you want the redirect to be temporary (302) then you can just remove the =permanent
part. Moved Temporarily is the default for the R
flag.
这篇关于mod_rewrite的:从URL删除查询字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文