[英]How to .htaccess redirect domain to subdomain while keeping the main domain intact
我想重定向我網域下的所有網址
domain.com/urls、www.domain.com/profile/user1.html等到subdomain.domain.com/urls和subdomain.domain.com/profile/user1.html等。
但我不想將domain.com和www.domain.com重定向到subdomain.domain.com
是否可以通過htaccess?
編輯:我只想重定向內部頁面和文件。 但是保留主要的domain.com。
更多例子
domain.com/page1.html to subdomain.domain.com/page1.html
www.domain.com/members/admin.html to subdomain.domain.com/members/admin.html
www.domain.com to www.domain.com (no redirection here)
嘗試:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/.+
RewriteCond %{REQUEST_URI} !^/index\.(php|htm)
RewriteCond %{HTTP_HOST} !^subdomain.domain.com$ [NC]
RewriteRule ^ http://subdomain.domain.com%{REQUEST_URI} [L,R]
如果要永久重定向,請將方括號更改為: [L,R=301]
。
您可以先處理首頁, 而不用第二條規則重寫和重定向其他所有內容
RewriteRule ^$ - [L]
RewriteCond %{HTTP_HOST} !^subdomain.domain.com$
RewriteRule ^.+$ http://subdomain.domain.com/$0 [R,L]
當一切按預期工作時,可以將R
更改為R=301
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.