繁体   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