如何將多個 url 重定向到我嘗試過但它不起作用的另一個 url
RewriteCond %{HTTP_HOST} ^sub.domain.to/q1$ [NC,OR]
RewriteCond %{HTTP_HOST} ^sub.domain.to/q2$ [NC,OR]
RewriteCond %{HTTP_HOST} ^sub.domain.to/q3$ [NC,OR]
RewriteCond %{HTTP_HOST} ^sub.domain.to/q4$ [NC,OR]
RewriteCond %{HTTP_HOST} ^sub.domain.to/q5$ [NC]
RewriteRule ^(.*)$ https://sub.domain.to/full-q [R=301,L]
uj5u.com熱心網友回復:
好的,當我添加時它起作用了 %{REQUEST_URI}
所以這行得通
RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^sub\.domain\.to/q1$ [NC,OR]
RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^sub\.domain\.to/q2$ [NC,OR]
RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^sub\.domain\.to/q3$ [NC,OR]
RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^sub\.domain\.to/q4$ [NC,OR]
RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^sub\.domain\.to/q5$ [NC]
RewriteRule ^(.*)$ https://sub.domain.to/full-q [R=301,L]
uj5u.com熱心網友回復:
HTTP_HOSTserver 變數包含 HTTP 請求標頭的值,Host即。僅主機名。這不包含 URL 路徑(即在您的示例/q1中/q2)。
該RewriteRule 模式與 URL 路徑匹配。
請嘗試以下操作:
RewriteCond %{HTTP_HOST} ^sub\.domain\.to [NC]
RewriteRule ^(q1|q2|q3|q4|q5)$ https://%{HTTP_HOST}/full-q [NC,R=301,L]
或者,在包含完整 URL 路徑的條件REQUEST_URI中使用服務器變數。例如:
RewriteCond %{HTTP_HOST} ^sub\.domain\.to [NC]
RewriteCond %{REQUEST_URI} ^/q1$ [NC,OR]
RewriteCond %{REQUEST_URI} ^/q2$ [NC,OR]
RewriteCond %{REQUEST_URI} ^/q3$ [NC,OR]
RewriteCond %{REQUEST_URI} ^/q4$ [NC,OR]
RewriteCond %{REQUEST_URI} ^/q5$ [NC]
RewriteRule ^ https://%{HTTP_HOST}/full-q [R=301,L]
使用 302(臨時)重定向進行測驗以避免潛在的快取問題,并且僅更改為 301(永久)重定向 - 如果這是有意的 - 一旦您確認它按預期作業。
您需要在測驗前清除瀏覽器快取。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/418294.html
標籤:
下一篇:為什么這些div總是重疊顯示?
