Create subdomain in .htaccess file

Sep2
  • Share/Bookmark

Difficulty: ★☆☆☆☆
Let’s say you have a website with a forum. For example:
http://www.mydomain.com/forum/?option=com_kunena&Itemid=0
you want to bind it to the following subdomain:
http://forum.mydomain.com

Then this is your .htaccess file content. (Do not forget the [R=301,L] or it won’t work)

RewriteEngine On
# first make sure my www is not touched
RewriteCond %{HTTP_HOST} !^www.mydomain.com
# the subdomain you want to create
RewriteCond %{HTTP_HOST} ^forum.mydomain.com
# the place to redirect to
RewriteRule (.*) http://www.mydomain.com/forum/?option=com_kunena&Itemid=0 [R=301,L]


Leave a comment