Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess redirect to subdomain

I'm tying to set up the scenario, if someone visits website.com/blog/ they are redirected to blog.website.com.

I used this code in my .htaccess file to achieve some other redirection (from .net to .com) previously:

Options +FollowSymLinks
RewriteEngine on  
RewriteCond %{HTTP_HOST} ^(www.|blog.)?website.net(.*) [NC]  
RewriteRule (.*) http://www.website.com/$1 [R=301,L]

It may also be relevant that I have an ErrorDocument 404 in my apache configuration file.

To solve my my problem I tried this:

Options +FollowSymLinks
RewriteEngine on  
RewriteCond %{HTTP_HOST} ^(www.|blog.)?website.net(.*) [NC]  
RewriteRule (.*) http://www.website.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^(www.)?website(.com|.net)/blog/?$ [NC]
RewriteRule (.*) http://blog.website.com/ [L]

This code however is not working. My error document is still handling the request (the /blog/ directory doesn't exist). I tried moving this new code above the ErrorDocument in the apache conf file, but the same thing occurred.

It's no doubt a syntactical error, any help would be greatly appreciated :)

like image 837
user1216981 Avatar asked Feb 17 '12 19:02

user1216981


People also ask

Can you redirect subdomain?

Under Modify a Subdomain, locate the domain you want to redirect, then click its Manage Redirection link on the right. In the text box, type the URL you would like visitors to be redirected to if they go to the subdomain sample1.hgexample.com. Click Save. You will see the redirected URL under the Redirection column.


1 Answers

in the .htaccess file in the root of your website.com directory

RewriteEngine on
RewriteBase / 

RedirectMatch 301 ^/blog/(.*)$ http://blog.website.com/$1
like image 170
Martin Avatar answered Nov 10 '22 03:11

Martin