我有一個網站被強制非 www(由托管)。我可以訪問 htaccess 檔案,并且正在嘗試將我的一些頁面重定向到另一個域。www 有效,非 www (這是當前的)它沒有重定向。這是我在 htaccess 中所擁有的
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Redirect 301 /my-slug-here https://anotherdomain.example/some-slug-here/
</IfModule>
uj5u.com熱心網友回復:
不建議同時使用Redirectfrommod_alias和RewriteRulefrom mod_rewrite。通過使用您的規則RewriteRule并將其置于前端控制器規則之上,您將獲得更好的結果。
我不建議將非 WordPress 規則放在該BEGIN WordPress部分中,因為 WordPress 可能會在升級程序中覆寫整個部分。我會將您的重定向規則放在 WordPress 部分之上,即使這意味著使用第二個RewriteEngine On
RewriteEngine On
RewriteRule ^/?my-slug-here https://anotherdomain.example/some-slug-here/ [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/359399.html
