skip to Main Content

I’ve been trying to redirect a subdomain to a subdirectory through htacess..

I have a domain lets say sub.domain.com and the directory domain.com/site/
I want to redirect sub.domain.com to domain.com/site not changing any url, simply redirecting in a SEO friendly way.

I’ve tried a redirect 301 rule but it doesn’t seem to have worked.

2

Answers


  1. Try this in your .htaccess:

    RedirectMatch 301 wiki.comp.tf(.*) comp.tf/wiki$1
    

    If that does not work, an alternative option is:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^wiki.comp.tf
    RewriteRule ^(.*)$ http://comp.tf/wiki$1 [L,NC,QSA]
    

    Some potential options for you using actual names:

    Redirect 301 wiki.comp.tf comp.tf/wiki
    
    Login or Signup to reply.
  2. You can use the following rule :

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^sub.domain.com$ [NC]
    RewriteRule ^(.*)$ /site/$1 [L]
    

    This will internally redirect

    • sub.domain.com

    to

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