最好用一個例子來解釋:
- If I enter either URLs in my brower :
- www.myhost.com/my-page.html?year=
- www.myhost.com/my-page.html
- I then want to get redirected to www.my-2nd-host.com/current-year/my-page.html
任何想法如何完成?謝謝你。
uj5u.com熱心網友回復:
您可以使用 mod_rewrite 這樣做:
RewriteEngine On
RewriteCond %{QUERY_STRING) !(^|&)year=[^&]
RewriteRule ^/?my-page\.html$ https://www.my-2nd-host.com/current-year/my-page.html [R=302,L]
正則運算式(^|&)year=[^&] 檢查是否存在year具有非空值的URL 引數。然后!前綴否定運算式,因此當該 URL 引數為空或根本不存在時它是成功的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/346048.html
