Forum Moderators: phranque
My english are not so good, i'm from Spain (Canary Islands).
I'm trying since two weeks to use the rewrite mod of Apache to use it to "create" subdomains.
I search at google, and in forums (spanish forums), but though there are examples, a lot of, and here at wemasterworld more, i can't bring it to run. Allways errors, or no errors, but not work.
I am driven to despair since I go some time trying to do that this works, but there is no way.
I know that in this forums are a lot of examples, but, until now, i've prove five or six, and no one have worked.
I think it's not a good idea post one of the thousend (not so much :P) of codes i've seen and trying, because i unknow where is the most correctly.
Thanks
Welcome to WebmasterWorld!
We have discussed many ways of doing this here at WebmasterWorld. Perhaps this search [google.com] will help you.
For background information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
Jim
I've tried some codes from webmasterworld, but anything works. The "best" (without errors when i try), is that one, from andreas.
RewriteEngine On
rewritecond %{http_host}_SPACE_!^$
rewritecond %{http_host}_SPACE_!^(www\.)?anydomain\.com$ [NC]
rewritecond %{http_host}<->%{REQUEST_URI} ^(www\.)?([^.]+).*<->/([^/]+)? [NC]
rewritecond %2<->%3_SPACE_!^(.*)<->\1$ [NC]
rewriterule ^(.+) /%2/$1 [PT,L]
Give no errors, but doesn't works. When i try to open a subdomain, there give me a 404 error.
I've put spaces before!, not _SPACE_.
I think it worked up to Apache 1.3.27 or so.
I wrote several different version of sub (and pointed) domain RewrireRules.
Here is one of them.
RewriteEngine on
RewriteBase /# Loop stopping and Virtual document root processing for CGI/PHP
#RewriteRule ^/*virtualdr.cgi - [L]
#RewriteRule ^/*[^./]+\.[^/]+/.*\.(cgi¦php5?)$ virtualdr.cgi [L]
RewriteRule ^/*[^./]+\.[^/]+/.*$ - [L]
# Code for missing Trailing slashe problem
RewriteCond s%{HTTPS} ^((s)on¦s.*)$
RewriteRule ^/*(.+/)?([^.]*[^/])$ http%2://%{HTTP_HOST}/$1$2/ [L,R=301]
# Sub/pointer domain rewrite code
RewriteCond %{HTTP_HOST}!^(www\.)?(MAINDOMAIN\.?COM¦USER) [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)$ [NC]
RewriteRule ^(.*)$ %2/$1
Directory layout:
/path-to-docroot/ <== MainDomain in docroot
/path-to-docroot/subdom1.maindomain.com/ <== Directory for sub domain
/path-to-docroot/subdom2.maindomain.com/ <== Directory for sub domain
/path-to-docroot/pointed-domain.com/ <== Directory for pointed domain
/path-to-docroot/sub.pointed-domain.com/ <== Directory for sub domain of pointed domain
The virtualdr.cgi prevents the problem of ugly URL and
some scripts simply failing when the docroot is presented differently.
I'll post URL for this and other code and explanation.
if it's allowed
If not, you can google and it appears near the top with "virtualdr.cgi".