Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

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

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

Comments

  • 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.

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

  • @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.

  • @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.

  • I've tired these codes also,

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

    and

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

    nothing works.

  • edited December 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.

  • 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.

  • 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:
    [code autolinks=”false”]
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^www.mywebsite.com
    RewriteRule ^blog/(.*)$ http://www.mywebsite.com/$1 [L,R=301]
    [/code]

    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.

Sign In or Register to comment.