在同一個域中,我想從到進行 301/this/old/path/file.pdf重定向/this/new/path#abc
我試過這個:
Redirect 301 /this/old/path/file.pdf /this/new/path#abc
它執行重定向,但顯示以下路徑:
/this/new/path#abc?/this/old/path/file.pdf
它應該是:
/this/new/path#abc
這里有什么問題的任何提示嗎?
---更新這是我的 .htaccess 檔案的內容 ussign just redirect
RewriteOptions inherit
Options FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Redirect 301 /this/old/path/file.pdf /this/new/path#abc
</IfModule>
并使用 RewriteRule
RewriteOptions inherit
Options FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{HTTP_HOST} ^mydomain.com$
RewriteRule /this/old/path/file.pdf /this/new/path#abc [NE,R=301]
</IfModule>
這不會進行任何重定向
不知道這是否重要,但我正在使用 CPanel。
uj5u.com熱心網友回復:
( Redirectmod_alias) 指令在 mod_rewriteRewriteRule指令之后應用,因此您會看到之前RewriteRule內部重寫應用的查詢字串。您基本上在 mod_alias 和 mod_rewrite 之間存在沖突。
您需要在現有規則之前RewriteRule使用 mod_rewrite指令,在指令之后立即使用。不是在最后。順序很重要。RewriteEngine
例如:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC]
RewriteRule ^this/old/path/file\.pdf$ /this/new/path#abc [NE,R=301,L]
請注意,RewriteRule 模式匹配的 URL 路徑不以斜杠開頭。該RewriteRule指令的第一個引數(模式)是一個正則運算式,因此需要應用必要的轉義和錨點。
如果您需要此規則僅適用于指定域,則檢查服務器變數的條件是必要的。HTTP_HOST
需要該NE標志來防止#字符在回應中被 URL 編碼(否定其含義是片段識別符號分隔符)。
您需要在測驗前清除瀏覽器快取。并首先使用 302(臨時)重定向進行測驗,以避免潛在的快取問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/459219.html
標籤:阿帕奇 .htaccess 重定向 codeigniter-3
