2013-01-15 96 views
1

奇怪问题的位,但我希望在我的所有URL上设置查询字符串。如果参数未设置(或为空),那么我想重定向以包含默认值。.htaccess中的默认查询字符串

例如:

example.com would need to requrect to example.com?param=a 

example.com?param would also need to redirect to example.com?param=a 

如果参数是设定,已知值的列表的一部分,那么它应该进行正常:

example.com?param=(a|b|c|d) would go to the respective page a,b,c or d 

该网站使用的部分页面其他参数进行排序和分页,所以规则不能认为这是唯一的查询字符串。

我已经试过几件事情,但一直得到坚持重定向循环。这是试图设置默认PARAM:

RewriteCond %{QUERY_STRING} !(^|&)param=(a|b|c|d)($|&) 
RewriteRule ^(.*)$ /index.php?rq=$1&param=a [L,QSA] 

主要CMS重写规则是:

RewriteCond %{REQUEST_URI} !^\/*(index\.php|blog|admin\/assets|site\/assets|robots.txt|sitemap(|\-[0-9]+)\.xml|products.xml|favicon\.ico) 
RewriteRule ^(.*)$ /index.php?rq=$1 [L,QSA] 

任何帮助将是巨大的!

回答

1
RewriteCond %{QUERY_STRING} !(^|&)param=(a|b|c|d)($|&) 
RewriteCond %{REQUEST_URI} !^\/*(index\.php|blog|admin\/assets|site\/assets|robots.txt|sitemap(|\-[0-9]+)\.xml|products.xml|favicon\.ico) 
RewriteRule ^(.*)$ $1?%{QUERY_STRING}&param=a [L] 

RewriteCond %{REQUEST_URI} !^\/*(index\.php|blog|admin\/assets|site\/assets|robots.txt|sitemap(|\-[0-9]+)\.xml|products.xml|favicon\.ico) 
RewriteRule ^(.*)$ /index.php?rq=$1 [L,QSA] 
+0

谢谢,这是几乎没有。我不得不改变的第一条规则读 重写规则^(。*)$ /index.php?rq=$1&%{QUERY_STRING}¶m=a [L] 如果未设置帕拉姆,我需要它来追加该到地址栏中的网址。这可能吗? –

+0

将[L]更改为[L,R = 301](在测试过程中使用302)。 – Gerben

+0

谢谢,这是添加参数,但我需要隐藏?rq =部分。基本上,我希望它重写URL,但只是追加?/&param =部分。这甚至有可能吗? –