skip to Main Content

The blog section of a website moved from a subdomain to a directory of the main domain. I need to redirect all users visiting blog.site.com to site.com/blog/ and the directory someone enters should be kept when forwarding, e.g. blog.site.com/post/welcome should point to site.com/blog/post/welcome

I treid adding this to my .htaccess file which I placed in the subdomain’s directory via FTP:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog.herderzeitung.de$ [OR]
RewriteCond %{HTTP_HOST} ^www.blog.herderzeitung.de$
RewriteRule (.*)$ https://herderzeitung.de/blog/$1 [R=301,L]

However, this doesn’t seem to be working. I was also wondering, what the most SEO friendly way is to achieve this (the site permanently moved to another domain).

Thanks in advance!

2

Answers


  1. Chosen as BEST ANSWER

    This seems to work:

    RewriteEngine On
    RewriteCond %{REQUEST_URI} (.*)
    RewriteRule ^(.*)$ https://herderzeitung.de/blog/$1 [L,R=301]
    

    Thank you everyone!


  2. Try

    RewriteEngine On
    RewriteCond %{HTTP_HOST}       ^blog.herderzeitung.de$ [OR]
    RewriteCond %{HTTP_HOST}  ^www.blog.herderzeitung.de$
    RewriteRule  ^/?(.*)$ https://herderzeitung.de/blog/$1 [R=302,L]
    

    I’ve escaped the dots, and anchored&normalized the pattern. Also switched it to temporary redirects (302); once you know it works, then change it to 301 again for SEO reasons.

    And yes, as far as i know 301s are the best method for retaining your search rankings and the like.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search