Welcome to WebmasterWorld Guest from 54.166.152.121

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

mod rewrite subdomains

     
8:59 am on Dec 27, 2009 (gmt 0)

5+ Year Member



Hello,
i have 1 domain for example .. my-domain.info
now i need automatic creation of subdomains by creating directory in root/sub/#*$!x .. i create by :

############################
RewriteEngine On
rewritebase /
php_flag register_globals on
Options +FollowSymLinks
Options -Indexes

RewriteCond %{HTTP_HOST} !^www\.my-domain\.info$ [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9-]+)\.my-domain\.info$ [NC]
RewriteRule ^(.*$) sub/%1/$1 [L]
############################

... sometime works, sometime no :( its true ?

i'd like if some directory (subdomain) isn't create .. so go 404.php .. now this write err500

---
my "dream" are :
automatic create subdomains with create directory

automatic-subdomain.my-domain.info/
=> my-domain.info/sub/automatic-subdomain/index.php

automatic-subdomain.my-domain.info/some
=> my-domain.info/sub/automatic-subdomain/some.php

automatic-subdomain.my-domain.info/some/somethink
=> my-domain.info/sub/automatic-subdomain/some.php?cat=somethink

automatic-subdomain.my-domain.info/some/somethink/somepage
=> my-domain.info/sub/automatic-subdomain/some.php?cat=somethink&page=somepage

many thanks.

6:03 pm on Dec 27, 2009 (gmt 0)

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



Two methods:

Rewrite only if the requested URL resolves to an existing directory and/or file in the /subs/ folder:


RewriteEngine On
RewriteBase /
php_flag register_globals on
Options +FollowSymLinks -Indexes
#
RewriteCond $1 !^sub/
RewriteCond %{HTTP_HOST} !^www\.my-domain\.info [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9\-]+)\.my-domain\.info
RewriteCond %{DOCUMENT_ROOT}/sub/%1/$1% -f [OR]
RewriteCond %{DOCUMENT_ROOT}/sub/%1/$1% -d
RewriteRule ^(.*)$ sub/%1/$1% [L]

-or-

Allow directory indexes of subdomain folders which do not have any index file:


RewriteEngine On
RewriteBase /
php_flag register_globals on
Options +FollowSymLinks [b]+I[/b]ndexes
#
RewriteCond $1 !^sub
RewriteCond %{HTTP_HOST} !^www\.my-domain\.info [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9\-]+)\.my-domain\.info
RewriteRule ^(.*)$ sub/%1/$1 [L]

Test both of these so that you can see how the server behaviour changes when there are no files in the 'new' subdomain's folder. Then pick the method you prefer. The first is more like your code, while the second will have much better performance because it does not have to go check the disk (twice) for each request. It is also simpler.

After you get the subdomain->folder rewrite working, then you can modify the code to rewrite to a script like "some.php".

The RewriteCond at the top prevents an 'infinite' rewriting loop.

Note that there are several other changes to patterns, anchoring, and flags. These are intended to avoid problems -- some of which could have been serious.

Jim

12:03 pm on Dec 29, 2009 (gmt 0)

5+ Year Member



many thanks.. i need change my requirements.
Now i change this htacces to.. its true ? and "secure" ?

###################################
RewriteEngine On
RewriteBase /
php_flag register_globals on
Options +FollowSymLinks +Indexes

RewriteCond $1 !^sub
RewriteCond %{HTTP_HOST} !^www\.my-domain\.info$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([[:alnum:]-]+)\.my-domain\.info$ [NC]
RewriteRule ^(.*$) sub/file.php?sub=%2 [L]
###################################

it makes ..
www.my-domain.info => www.my-domain.info/index.php

(www.)subdomain.my-domain.info => www.my-domain.info/sub/file.php?sub=subdomain

(www.)subdomain.my-domain.info/somethink/else/ => www.my-domain.info/sub/file.php?sub=subdomain

and by php > REQUEST_URI .. i will get "/somethink/else/", where i explode "/" and i get category, page etc. by position in url.

I want to using by 1 file - file.php, where i need know so i have this subdomains, and im in this location.

its possible or somewhere have better idea ?

3:04 pm on Dec 29, 2009 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



You have a URL on both sides of your requirements list, above. Are you wanting an external redirect?

If this is supposed to be an internal rewrite, the right hand side will be an internal filepath not a URL.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month