默认的查询字符串在.htaccess [英] Default Query String in .htaccess
问题描述
一个奇怪的问题位,但我想对我所有的网址设置查询字符串。如果没有设置参数(或为空),那么我想重定向到包含默认。
例如:
example.com需要requrect到example.com?param=a
example.com?param还需要重定向到example.com?param=a
如果该参数设置,是已知值列表的一部分,那么它应该进行正常的:
example.com?param=(A | B | C | D)会去到各个页面的A,B,C或D
该网站的部分页面使用其他参数进行排序和分页,所以规则不能想当然地认为这是唯一的查询字符串。
我试了几件事情,但一直得到卡在重定向循环。这是试图设置默认参数:
! 的RewriteCond%{QUERY_STRING}(^ |&安培;)参数=(A | B | C | D)($ |&安培;)
重写规则^(。*)$ /index.php?rq=$1¶m=a [L,QSA]
主要CMS重写规则是:
的RewriteCond%{REQUEST_URI} !^\/*(index\.php|blog|admin\/assets|site\/assets|robots.txt|sitemap(|\-[0-9]+)\.xml|products.xml|favicon\.ico)
重写规则^(。*)$ /index.php?rq=$1 [L,QSA]
任何帮助将是巨大的!
的RewriteCond%{QUERY_STRING}(^ |&安培)!参数=(A | B | C | D)( $ |和放大器;)
的RewriteCond%{REQUEST_URI} !^\/*(index\.php|blog|admin\/assets|site\/assets|robots.txt|sitemap(|\-[0-9]+)\.xml|products.xml|favicon\.ico)
重写规则^(。*)$ $ 1%{QUERY_STRING}&放大器;参数=一[L]
的RewriteCond%{REQUEST_URI} !^\/*(index\.php|blog|admin\/assets|site\/assets|robots.txt|sitemap(|\-[0-9]+)\.xml|products.xml|favicon\.ico)
重写规则^(。*)$ /index.php?rq=$1 [L,QSA]
Bit of an odd question, but I'd like to have a query string set on all of my URLs. If the parameter isn't set (or is empty), then I'd like to redirect to include a default.
For example:
example.com would need to requrect to example.com?param=a
example.com?param would also need to redirect to example.com?param=a
If the param is set and is part of a list of known values, then it should carry on as normal:
example.com?param=(a|b|c|d) would go to the respective page a,b,c or d
Some pages of the site use other parameters to sort and paginate, so the rules cannot assume that this is the only query string.
I've tried a couple of things, but kept getting stuck in a redirect loop. This is trying to set the default param:
RewriteCond %{QUERY_STRING} !(^|&)param=(a|b|c|d)($|&)
RewriteRule ^(.*)$ /index.php?rq=$1¶m=a [L,QSA]
The main CMS rewrite rule is:
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]
Any help would be great!
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}¶m=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]
这篇关于默认的查询字符串在.htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!