Mobile app version of vmapp.org
Login or Join
Steve110

: Redirect/Rewrite Subdomain to Subfolder I'm trying to redirect a subdomain to a subfolder e.g. forums.domain.com to www.domain.com/forums Note that I started the forums in the subfolder format but

@Steve110

Posted in: #Dns #Htaccess #Redirects #Subdomain

I'm trying to redirect a subdomain to a subfolder e.g. forums.domain.com to domain.com/forums
Note that I started the forums in the subfolder format but worried that members might mistakenly try to access the forums using the subdomain format.

RewriteCond %{HTTP_HOST} ^(www.)?forums.domain.com
RewriteRule .* /forums [L]


From what I read the codes above should work through .htaccess, but do I still need to create a DNS A record to point to the IP address of the server?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Steve110

2 Comments

Sorted by latest first Latest Oldest Best

 

@Smith883

Without having to specify a domain in the circumstance that multiple domains point to the website root or that a production .htaccess rules can be applied to:

RewriteCond %{HTTP_HOST} ^(.*).ANYdomain.com [NC]

10% popularity Vote Up Vote Down


 

@Kevin317

Try this:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www). [NC]
RewriteCond %{HTTP_HOST} ^(.*).domain.com [NC]
RewriteRule (.*) www.domain.com/%1 [R=301,L]


This is generic and will redirect all subdomains to a subdirectory. If you have only one subdomain you want to redirect you can hardcode it in.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme