Ask Your Question
0

How can I redirect all subdomains to the www folder using htaccess?

asked 2021-07-28 11:00:00 +0000

nofretete gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-02-02 20:00:00 +0000

djk gravatar image

You can redirect all subdomains to the www folder using the following code in your .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/%1/$1 [L,R=301]

This code will redirect any subdomain (except for www) to the www folder with the subdomain name added as a directory. For example, test.example.com would be redirected to www.example.com/test/.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-07-28 11:00:00 +0000

Seen: 12 times

Last updated: Feb 02 '22