我在 .htaac??ess 檔案中使用了這個重定向命令。
Redirect 301 /old-path.html /new-path.html
它向我展示 /new-path.html?page=old-path
概率,附加引數是我的 htaccess 中一些 RewriteRule 和 RewiteCond 的結果。
我不喜歡編輯我原來的 htaccess 代碼。
我發現下面的命令非常接近結果。
RedirectMatch 301 /old-path.html /new-path.html?
結果是/new-path.html? 它只有一個額外的?
uj5u.com熱心網友回復:
不要使用,RedirectMatch因為它沒有辦法丟棄舊的/以前的查詢字串。
最好使用RewriteRule這樣的:
RewriteRule ^old-path\.html$ /new-path.html? [L,R=301,NC]
尾隨?目標將丟棄任何查詢字串。
在 Apache 2.4 上,您還可以使用:
RewriteRule ^old-path\.html$ /new-path.html [L,R=301,NC,QSD]
作為一個拇指規則,將所有R=...規則放在其他規則之前的.htaccess之上。這將使這些規則在其他可能修改請求 URI 或查詢字串的內部重寫規則之前起作用。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/380231.html
上一篇:如何使用JavaScript通過HTTP請求從IBMCloud獲取JSON格式的資料?
下一篇:如何通過IP限制對特定重寫的訪問
