我需要重寫網址:
mydomain.com/index.php -> mydomain.com
我嘗試使用:
RewriteRule ^index.php$ /$1 [R=301,L]
問題 - 使用這個 url 重寫 mydomain.com/index.php?(看看最后的問號)也被重定向。需要重寫 url 以完全匹配 mydomain.com/index.php 而不在末尾添加任何內容(引數等)。
補充說明:
mydomain.com/index.php?abc不必重寫
只是mydomain.com/index.php -> mydomain.com
uj5u.com熱心網友回復:
您可以使用RewriteCondwith執行此操作THE_REQUEST:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/ index\.php\s [NC]
RewriteRule ^ / [L,R=302]
確認它作業正常后,替換R=302為R=301. 測驗規則時避免使用R=301(永久重定向) 。mod_rewrite
THE_REQUEST變數表示 Apache 從您的瀏覽器收到的原始請求,并且在執行其他重寫指令后它不會被覆寫。此變數的示例值為GET /index.php?id=123 HTTP/1.1
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/449230.html
