這是我的 htaccess:
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/view.php$
RewriteCond %{QUERY_STRING} ^. $
RewriteCond %{QUERY_STRING} ^(?!(mk=[1-9][0-9]{0,1}|id=[1-9][0-9]{0,3})$).*$
RewriteRule ^view.php$ https://www.example.com/view.php? [L,R=301]
一切正常:
1) non-www > www and http>https redirects...
2) Checking of values of query parameters "id" and "mk",
whether they are well formatted or not according the to following requirements below:
"id" range: 1-9999 (without leading "0" from 1 to 9999)
"id": always lowercase, no "Id" or "ID" or "iD"
和
"mk" range: 1-99 (without leading "0" from 1 to 99)
"mk": always lowercase, no "Mk" or "MK" or "mK"
如果“id”和“mk”值不符合這些規則(例如 id=qwe),那么我洗掉例外查詢字串并將其重定向到通用 view.php url:
https://www.example.com/view.php
我面臨的唯一問題是 Facebook 鏈接到我的網站,它們具有以下結構,我想保留:
https://www.example.com/view.php?id=123&fbclid=IwAR05VGnAct....
我的 htaccess 洗掉了整個查詢字串,因為它認為 id=123&xxxx 已經是格式例外的查詢,所以沒有轉到特定頁面:
view.php?id=123
它轉到:
view.php
這是不好的,因為它是不同的內容。
因此,問題是如何從 Facebook 鏈接的查詢字串規范化規則中例外,即不洗掉:
?id=123&fbclid=IwAR05VGnAct....
uj5u.com熱心網友回復:
您可以使用:
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/view\.php$
RewriteCond %{QUERY_STRING} ^(?!(mk=[1-9]\d?|id=[1-9]\d{0,3})(&|$)).
RewriteRule ^ https://www.example.com%{REQUEST_URI}? [L,R=301]
這將正確地視為或引數的&終止,因此將允許作為查詢字串。idmkid=123&fbclid=IwAR05VGnAct
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/376344.html
上一篇:列作為值/SQL中的非透視表
下一篇:Apache虛擬主機子域不起作用
