Redirect for .htaccess Wildcard Subdomains
Posted
by waywardspooky
on Stack Overflow
See other posts from Stack Overflow
or by waywardspooky
Published on 2010-06-14T14:24:27Z
Indexed on
2010/06/15
1:42 UTC
Read the original article
Hit count: 259
Hello, I've been trying to figure out a way to redirect requests for wildcard subdomains to a specific folder ( called 'core' ) and calling the requested page/file from that specific folder. For example, making all calls to -http://johnny5.mysite.net redirect to -http://mysite.net/core/, or -http://docholliday.mysite.net/login.php redirect to -http://mysite.net/core/login.php, or a final example, -http://jamesbrown.mysite.net/images/feelgood.jpg to -http://mysite.net/core/images/feelgood.jpg.
The problem I've been having has been getting the redirect to call the requested page/file from 'core'. I've been able to get the wildcard subdomains to redirect requested pages/files to the root ( -http://mysite.net ), but not to the specific folder ( -http://mysite.net/core/ ).
Here's what I have:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^(www|mail|ftp)\.[a-z-]+\.[a-z]{2,6} [NC]
RewriteCond %{HTTP_HOST} ([a-z-]+\.[a-z]{2,6})$ [NC]
RewriteRule ^/(.*)$ http://%1/core/$1 [L]
I've tried several things like removing the http://%1 in the RewriteRule but I can't seem to get it to work in the way I described above.
© Stack Overflow or respective owner