簡體   English   中英

如何重定向httaccess

[英]How to redirect httaccess

我嘗試重定向但沒有工作,即使我從 web 中獲取了正確的代碼。

Redirect /index.php?page=8 /?page=8
 Redirect /index.php?page=8 /?page=8

mod_alias Redirect指令與查詢字符串不匹配,因此上述指令永遠不會匹配,所以什么也不做。

要從可見的 URL 中刪除index.php (目錄索引),您需要在.htaccess文件的頂部使用 mod_rewrite。 例如:

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php$ / [R=301,L]

以上將 /index.php?page=8 形式的/index.php?page=8重定向到/?page=8 初始請求中存在的任何查詢字符串都簡單地傳遞給目標/替換而不改變。

檢查REDIRECT_STATUS env var 的條件確保我們不會得到由 mod_dir (或 Laravel 前控制器)將請求重寫為index.php引起的重定向循環。

清除瀏覽器緩存並首先使用 302(臨時)重定向進行測試。


但是,如果您只想將特定的 URL /index.php?page=8 (如問題中所述)重定向到/?page=8那么您應該編寫如下規則:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,7}\s/index\.php?page=8\sHTTP
RewriteRule ^index\.php$ / [R=301,L]

您的 htaccess 代碼應該是。

RewriteEngine On
RewriteRule ^index.php?page=$1 /?page=$1 [R=301,NC,L]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM