Reputation: 151
I have a main site hosted on Heroku and a Wordpress blog hosted on Bluehost. To get to the blog, a user types in blog.example.com
and it works. However, how would I redirect the URL so that when the user types in blog.example.com
the URL changes to example.com/blog
?
I added these two commands into the .htaccess
file and the site goes into a redirect loop:
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com$
RewriteRule ^ http://example.com/blog/%1 [L,R=301]
This is what I have in the .htaccess file so far (Wordpress default):
RewriteEngine on
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Thanks!
Upvotes: 0
Views: 41
Reputation: 2142
You can't, This isn't a simple htaccess issue
Unless your Blog is hosted to example.com
as well, or you OWN
both DNS record
blog.example.com
is a domain pointer, and example.com
could be pointed to another different locations.
to rewrite all your URL to another domain, it has to be hosted there or else the DNS record will never hit the wordpress to begin with.
Incase you own both, You can point dns for blog.example.com
to the same place as example.com
then in wordpress site setting change your wordpress site url to example.com/blog
Note WORDPRESS is hosted on example.com
domain
Upvotes: 1