spacing
spacing

Reputation: 780

Redirecting subdomain to subdirectory through htaccess

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.

Upvotes: 1

Views: 3137

Answers (2)

Joe
Joe

Reputation: 4897

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

Upvotes: 1

Amit Verma
Amit Verma

Reputation: 41249

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/

Upvotes: 1

Related Questions