[英].HTACCESS Redirect 301 all files from root directory to sub directory
[英].htaccess 301 redirect subdomain and all files and folders to root
為了解決這個問題,我整天頭頂在牆上。 如果您知道該怎么做並可以提供幫助,將不勝感激。
我正在嘗試將所有內容從www.example.com重定向到example.com的根域
以下方法可以按預期的方向重定向www.example.com,但對其他文件或文件夾的請求返回302。這是Wordpress Multisite安裝,但此時僅映射了一個域。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# BEGIN WordPress
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
# END WordPress
# Link re-directs from old website.
RewriteCond %{HTTP_HOST} ^www.example.com/(.*)$ [NC]
RewriteRule ^/?(.*)$ http://example.com$1 [R=301,L]
# Other
php_value memory_limit 500M
有人可以幫忙嗎? 謝謝,麻煩您了。
您需要在所有路由規則(例如wordpress的東西) 之前添加重定向規則。 您還缺少一個斜杠你的目標和HTTP_HOST 不包含任何路徑信息,只是主機名。 所以這:
# Link re-directs from old website.
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^/?(.*)$ http://example.com/$1 [R=301,L]
需要直接在htaccess文件頂部的RewriteEngine On
下。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.