Add a redirect old subdomain URL to main domain using .htaccess file


#1

I move my site to Infinity Free, use to have a blog on a sub-domain www.mysite.com/blog, want to have that redirected to my landing page www.mysite.com. Does Infinity Free allow it? If so what is the code I would use. The coding I used to do it did not work. I used:

RewriteEngine On RewriteCond %{HTTP_HOST} ^mysite.com/blog$ [NC] RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]

Would appreciate assistance on this, Thanks


#2

I think uour htaccess rules isn’t correct, you’d better to learn more about rewrite_mod in internet, it’s allowed to redirect users with that way.


#3

Where did you upload this .htaccess code? I checked your account but there was no .htaccess file there.


#4

@Admin said:
Where did you upload this .htaccess code? I checked your account but there was no .htaccess file there.

I deleted it since it did not work. I put it in the htdocs section.


#5

@DennisM said:

@Admin said:
Where did you upload this .htaccess code? I checked your account but there was no .htaccess file there.

I deleted it since it did not work. I put it in the htdocs section.

Upon closer inspection of the code, the RewriteCond looks like it’s not going to work.

I think you can forgo mod_rewrite entirely and just put Redirect /blog http://www.mysite.com in the file instead.


#6

I’ve tired these codes also,

RewriteRule ^blog/(.*)$ http://www.mywebsite.com/$1 [L,R=301]

and

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.mywebsite.com
RewriteRule ^blog/(.*)$ http://www.mywebsite.com/$1 [L,R=301]

nothing works.


#7

I go mywebsite.com/blog/ to redirect with

[code autolinks=”false”]
RewriteEngine On
RewriteRule ^blog/(.*)$ http://www.mywebsite.com/$1 [L,R=301]

But none of the blog post that under mywebsite.com/blog/ are only the main blog page is. I need all blog post to move.


#8

Able to work it out, had to do with the way WP posted the post. It is redirecting the main blog location just fine now. Thank you Admin for helping.


#9

Did you try the Redirect statement I proposed? I’m happy to try and help you, but I can’t help you if you don’t follow any suggestions and just keep writing your own rules which don’t work.

@DennisM said:
I’ve tired these codes also,

RewriteRule ^blog/(.*)$ http://www.mywebsite.com/$1 [L,R=301]

I don’t think that RewriteRule could ever be matched. If anything, it should be ^/blog(.*)$, because a request URI always starts with a slash.

@DennisM said:

RewriteEngine On
> RewriteBase /
> RewriteCond %{HTTP_HOST} ^www.mywebsite.com
> RewriteRule ^blog/(.*)$ http://www.mywebsite.com/$1 [L,R=301]

nothing works.

This RewriteRule is exactly the same as above, so will also never be matched. The only difference being that it only works on www.mywebsite.com and not on mywebsite.com.


#10

Prior anything else, could you let me know what platform you are using with your site? If it’s WordPress or something else. Because I’ve been in this situation before. Probably I could dig up some notes I’ve used before to recommend you something that worked for me. Be right back