问题原文
原帖链接 · 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.)
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
