1

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.

0

2 Answers 2

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 
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks, as I've said above, I've tried both yours and starkeen solution but it still displays the same error on the subdomain "server DNS address could not be found."
What are the actual domain and directory?
wiki.comp.tf is the subdomain which I want to redirect to comp.tf/wiki , I've changed those in your and starkeen code obviously to match my domain but I haven't been sucessful. Wondering if this has anything to do with my VestaCP setup but I've gone through it all 3 times and didn't find any issue
I've updated my previous options with the correct names now, just in case. I've also added one other simple 301 redirect.
It worked! Thanks, apparently I think I also forgot to set it up properly on cloudflare and didnt give it enough time to propagate the dns changes, so I think that was the main issue.
1

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/

3 Comments

Should I put this on the htaccess of the main domain or the htaccess of the sub domain, because Im using VestaCP on a VPS and it automatically creates different directories for each domain/subdomain created. And if I have to put it on the main htaccess what should I do about the htaccess of the subdomain directory?
You can use this inside the subdomain/.htaccess.
Thanks, I've tried both yours and thickguru solution but it still displays the same error on the subdomain "server DNS address could not be found."

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.