默认的查询字符串在.htaccess字符串、htaccess

2023-09-02 11:28:05 作者:4.Edge(边缘)

一个奇怪的问题位,但我想对我所有的网址设置查询字符串。如果没有设置参数(或为空),那么我想重定向到包含默认。

例如:

  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
 
Win10 1909怎么自动登录 Win10 1909自动登录设置方法 win10之家中文网

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

我试了几件事情,但一直得到卡在重定向循环。这是试图设置默认参数:

 的RewriteCond%{QUERY_STRING}(^ |&安培;)参数=(A | B | C | D)($ |&安培;)
重写规则^(。*)$ /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)
重写规则^(。*)$ /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&param=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}&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]