Mobile app version of vmapp.org
Login or Join
Miguel251

: Htaccess redirect a page from root domain to subdomain same name page on my Wordpress site, I need to http://example.com/page1/ redirect to http://site.example.com/page1/ I have tried this: <IfModule

@Miguel251

Posted in: #301Redirect #Htaccess #Redirects #Wordpress

on my Wordpress site, I need to
example.com/page1/

redirect to
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.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Miguel251

2 Comments

Sorted by latest first Latest Oldest Best

 

@Alves908

Also you can try this solution by replacing rewrite rule with below line in the .htaccess.

Redirect /page1/ site.example.com/page1/

10% popularity Vote Up Vote Down


 

@Alves908

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/$ 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.)

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme