Trying to implement subdomains with htaccess.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.
RewriteCond %{HTTP_HOST} ^([a-z0-9]+)\.domain.com(.*)$
RewriteRule ^(.*)$ http://domain.com/index.php?/public_site/main/%1/$1 [L]
</IfModule>
when i enter ahser.domain.com the browser URL is changing. is there a htaccess option to not let this happen when absolute URLs is used in RewriteRule?
Don’t rewrite to a full URL with domain in it. That generates a redirect since it’s going to a different website! You could put
microsoft.comthere; so how would it work without redirecting?What you have to do is make sure that the web pages work under the original domain. So when the client asks for
myname.domain.com/...how about rewriting that tomyname.domain.com/index.php?public_site/main/myname/.... Keep the domain the same. Theindex.php?can be made to work in any of those domains. For instance, even this could work:I.e. set it up so it doesn’t matter which virtual host accesses that path.
Once you have that, the rewrite can then just do:
You have to be careful not to introduce a loop since you’re now redirecting a URL to a longer URL which matches the same rewrite rulethe same domain. You need an additional
RewriteCondnot to apply this rewrite if the URL already starts with/index.php?public_site/.