Forum Moderators: phranque

Message Too Old, No Replies

virtual subdomain with 2 parameters

modrewrite

         

adresanet

9:31 am on Sep 28, 2010 (gmt 0)

10+ Year Member




hello ppl,

please help me with a solution for my problem:

i need to use a script with 2 parameters, but with subdomains

i need to get
http://subdomain.domain.com/more_pages

For
http://subdomain.domain.com/
I use the followings:

RewriteCond %{HTTP_HOST} !^www\.domain\.com?$
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com?$
RewriteRule ^$ /subdomain-type.php?subdomain=%1 [L]


but I don't know how to use for: subdomain-type.php?par1=$1&par2=$2

thanks!

jdMorgan

3:08 pm on Sep 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That depends on where you intend to get the "par2" variable from.

If this variable is already attached to the requested URL as a query string and you wish to keep it, then use the [QSA] flag -- Query String Append. This causes the "par1" name/value to be appended to the query string that is already attached to he requested URL, instead of replacing it.

RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com
RewriteRule ^$ /subdomain-type.php?subdomain=%1 [QSA,L]

Note other minor corrections.

If you intend to take the "par2" value form some other field in the requested URL, then we need to know where it will be.

Jim

adresanet

3:28 pm on Sep 28, 2010 (gmt 0)

10+ Year Member



I would like to have something like this:

http:// subdomain.domain.com/more_pages

where subdomain is first parameter and more_pages will be the second parameter

more_pages may be string or number

in my script i will know subdomain value with $_GET['subdomain'] but how will i know more_pages ?

jdMorgan

1:17 pm on Sep 30, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com
RewriteRule ^(/.*)?$ /subdomain-type.php?subdomain=%1&par2=$2 [L]

If you use only this new rule, then be aware of the following three things:
1) Subdomains can no longer have "real" subdirectories below them, because all subdirectory names will now be rewritten to "par2". If such "real" subdirectories are needed (for example, to store images, etc.), then these subdirectory-paths will need to be excluded from being rewritten -- either explicitly, or by using a "directory-exists" check in the rule.
2) If a subdirectory is not present in the "friendly" URL, "par2" will still be passed, but its value will be blank. If this is not acceptable, then you must use both rules, and remove the "?" from the new RewriteRule's pattern.
3) In your script, consistent with your question and your original code, you will use $_GET['par1'] and $_GET['par2']

Jim

adresanet

2:13 pm on Sep 30, 2010 (gmt 0)

10+ Year Member



thank you Jim!