user3961151
user3961151

Reputation:

Wildcard Subdomain to subfolder

how can I do that when a user enters to a subdomain (I'll have a wildcard subdomain), he will see what in the subfolder with the same name in the main domain? For example, if user will enter to works.domain.com, I want him to see what's in www.domain.com/works. Another example: user will enter to private.domain.com/photos/gallery.php?from=germany&no=3, he'll see what's in www.domain.com/private/photos/gallery.php?from=germany&no=3.

What should I write in the HTACCESS of the wildcard subdomain? Thanks!

Upvotes: 2

Views: 441

Answers (1)

Justin Iurman
Justin Iurman

Reputation: 19016

You can put this code in your htaccess (in document root folder)

RewriteEngine On

RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.domain\.com$
RewriteCond %1::%{REQUEST_URI} !^(.*?)::/\1/?
RewriteRule ^(.*)$ /%1/$1 [L,QSA]

Upvotes: 1

Related Questions