Forum Moderators: phranque
one.mydomain.com
two.mydomain.com
three.mydomain.com
ALL point to [mydomain.com...]
Basically i want to create "fake" subdomains using mod_rewrite and have them point to the dir of [mydomain.com...] so that the subdomains read the content in the main dir.
Is this possible?
Thanks a lot.
In short, it's easy to do what you're asking about, but there is little potential benefit and much risk.
Jim
[ONE.mydomain.com...]
ONE is got using PHP, same for if ONE was called TWO, php would get whatever the subdomain was and turn it into a variable.
Basically im using just one set of code in the main directy of the website, but i was subdomain to points to them so the code in the main dir gets the right data from the database.
For example
ONE.mydomin.com will get data from database
`one_news`
and TWO would pull
`two_news`
RewriteEngine on
# Redirect subdomain 'whatever' to subdirectory /'whatever' - except for 'www.' and 'mail.'
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} !^mail\.
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com
RewriteCond %{REQUEST_URI} !^/mydata/
RewriteRule (.*) /mydata/%1/$1 [L]
RewriteEngine on
# Redirect subdomain requests to /your_script.php - except for 'www.' and 'mail.'
RewriteCond $1 !^your_script\.php$
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} !^mail\.
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule (.*) /your_script.php?subdomain=%1&URL_path=$1 [QSA,L]
RewriteEngine on
# Redirect subdomain requests to /your_script.php - except for 'www.' and 'mail.'
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} !^mail\.
RewriteCond %{HTTP_HOST} ^[^.]+\.example\.com
RewriteRule !^your_script\.php$ /your_script.php [L]
thats what im using.
one.example.co.uk brings up nothing
[edited by: jdMorgan at 9:30 pm (utc) on Nov. 17, 2007]
[edit reason] examplified per Terms of Service. [/edit]
RewriteEngine On
# Redirect subdomain 'whatever' to subdirectory /'whatever' - except for 'www.' and 'mail.'
RewriteCond %{HTTP_HOST}!^www\.
RewriteCond %{HTTP_HOST}!^mail\.
RewriteCond %{HTTP_HOST} ^(.+)\.example\.co.uk
RewriteCond %{REQUEST_URL}!^/one/
RewriteRule (.*) /one/%1/$1 [L]
and its redirecting me to
http://search.live.com/results.aspxFORM=DNSAS&q=one.example.co.uk
when i goto one.example.co.uk
[edited by: jdMorgan at 10:06 pm (utc) on Nov. 17, 2007]
[edit reason] example.com [/edit]
[edited by: jdMorgan at 9:59 pm (utc) on Nov. 17, 2007]
[edit reason] example.com [/edit]
Understand that mod_rewrite code must be exactly, precisely correct to the very last character; The parser is very simple, efficient, and fast, and therefore, utterly unforgiving. mod_rewrite is not a high-level programming/scripting language; It does not allow wide variations in 'style'.
If you are making changes to the code, we need to see the code. Otherwise, we're just guessing.
Please use example.com or example.co.uk to avoid problems for both WebmasterWorld and for your site.
Also, it appears that you've ignored several of the previous errors I have pointed out. Perhaps a top-to-bottom review of this thread would help you.
Jim
[edited by: jdMorgan at 10:08 pm (utc) on Nov. 17, 2007]
this is the mod_rewrite im using and its giving the 500 error.
and in my error log i get
RewriteCond: bad flag delimiters
RewriteEngine on
# Redirect subdomain 'whatever' to subdirectory /'whatever' - except for 'www.' and 'mail.'
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} !^mail\.
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.co\uk
RewriteCond %{REQUEST_URI} !^/one/
RewriteRule (.*) /one/%1/$1 [L]
Be aware that you will get a 404 error if /one/<subdomain>/<requested_URL-path> does not exist. You have changed the target URL-path in the RewriteRule so that it no longer rewrites to a script, but have not mentioned why you did this.
Jim
RewriteEngine on
# Redirect subdomain 'whatever' to subdirectory /'whatever' - except for 'www.' and 'mail.'
RewriteCond %{HTTP_HOST}!^www\.
RewriteCond %{HTTP_HOST}!^mail\.
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.co\uk
RewriteCond %{REQUEST_URI}!^/one/
RewriteRule (.*) /one/%1/$1 [L]
so one.example.co.uk will not point to www.example.co.uk
thats what i need lol
# tables in the database would be
`teamname_news`
`teamname_members`
`teamname1_news`
`teamname1_members`
`teamname2_news`
`teamname2_members`
Going to teamname.mydomain.com would use the code in the /www dir and extract
`teamname_news`
`teamname_members`
because of the subdomain being teamname.
If the subdomain was teamname1.mydomain.com it would extract
`teamname1_news`
`teamname1_members`
because of the subdomain being teamname1.
But it is still using the same peice of code from /www
How would this be done?