homepage Welcome to WebmasterWorld Guest from 54.227.20.250
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Mod rewrite for subdomains
mod rewrite for subdomains
pzin

5+ Year Member



 
Msg#: 5376 posted 2:28 am on Jan 19, 2006 (gmt 0)

Hello to all.

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

 

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 5376 posted 3:14 am on Jan 19, 2006 (gmt 0)

pzin,

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

pzin

5+ Year Member



 
Msg#: 5376 posted 12:48 pm on Jan 20, 2006 (gmt 0)

Hello another one.

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_.

pzin

5+ Year Member



 
Msg#: 5376 posted 5:39 pm on Jan 20, 2006 (gmt 0)

I remenber, a time ago... That i've change some things in httpd.conf, but, PLESK (i use plesk), change me my configuration to plesk's configuration, the i must use htaccess to configure these things.

It's possible, that the code above don't work because i use PLESK?

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 5376 posted 10:46 pm on Jan 20, 2006 (gmt 0)

I don't know about Plesk, but many control panels create a separate subdirectory for each subdomain, and then add code to httpd.conf to 'send' user requests for that subdomain directly to that suddirectory. Therefore, no centralized .htaccess file can handle all subdomains.

Jim

extras

5+ Year Member



 
Msg#: 5376 posted 7:33 pm on Jan 21, 2006 (gmt 0)

The backref \1 in this part doesn't work in the newer version fo Apache1.3, AFAIK.
rewritecond %2<->%3_SPACE_!^(.*)<->\1$ [NC]

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".

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved