大网数据广告活动
网站运营与故障问答

htaccess redirect a page from root domain to subdomain same name page

· 52CE 我爱测

on my Wordpress site, I need to http://example.com/page1/ redirect to http://site.example.com/page1/ I have tried this: <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^example\.com$ [OR] RewriteC…

问题原文

原帖链接 · atul · CC BY-SA 3.0

on my Wordpress site, I need to

http://example.com/page1/

redirect to

http://site.example.com/page1/

I have tried this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^page1$ "http\:\/\/site\.example\.com\/page1\/" [R=301,L]
</IfModule>

The above did not work. I also removed the double quotes and escape slashes and just directly put the url, but no success. I will really appreciate the help.

已采纳解答

原帖链接 · MrWhite · CC BY-SA 3.0

http://example.com/page1/

RewriteRule ^page1$ ....

You are missing a trailing slash on the end of the RewriteRule pattern. Try the following in the .htaccess file at example.com's document root. This will need to go before any existing WordPress rewrites.

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^page1/$ http://site.example.com/page1/ [R=301,L]

I also removed the double quotes and escape slashes ...

Yes, no need for the plethora of backslash escapes. That looks like one of cPanel's attempts.

Also, no need for the <IfModule> wrapper, unless this is expected to "work" without mod_rewrite installed?

The RewriteBase directive is also superfluous here. (Note that you should only have one RewriteBase directive in your .htaccess file - WordPress usually writes this already.)

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2016-09-27)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。