簡體   English   中英

htaccess 301重定向到子域

[英]htaccess 301 Redirect to Subdomain

我正在嘗試僅將域中的子目錄頁面重定向到子域。 例如,我想要:

http://www.example.com/test.htm

http://shop.example.com/test.htm

我在htaccess文件中使用的RedirectMatch是:

RedirectMatch 301 http://www.example.com/(.*) http://shop.example.com/$1

我不確定為什么這行不通?

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^/?test\.htm$ http://shop.example.com/test.htm [R,L]

對於任何URL,它將是

RewriteRule ^/?(.*)$ http://shop.example.com/$1 [R,L]

/? 允許在.htaccess或服務器的配置中使用此規則。

另一個簡單的方法

RewriteEngine on
RewriteCond %{HTTP_HOST} ^http://www.example.com/test.htm[NC]
RewriteRule ^(.*)$ http://shop.example.com/test.htm[L,R=301,NC] 

暫無
暫無

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

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