URL ReWrite SubDomains
13 posts
• Page 1 of 1
URL ReWrite SubDomains
Is it possible to
Rewrite
http://subdomain.mydomain.com/..
to http://mydomain.com/subdomain/..
and
http://(www).yourdomain.com/..(with or without www)
to http://mydomain.com/yourdomain-com/...
Query strings and virtual directories will pass along
Thank you
Rewrite
http://subdomain.mydomain.com/..
to http://mydomain.com/subdomain/..
and
http://(www).yourdomain.com/..(with or without www)
to http://mydomain.com/yourdomain-com/...
Query strings and virtual directories will pass along
Thank you
- HeliconAndrew
-
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: URL ReWrite SubDomains
Hello,
Sure, try something like:
Regards
Sure, try something like:
- Code: Select all
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP:Host} ^(?:www\.)?yourdomain\.com$
RewriteRule (.*) http://mydomain.com/yourdomain-com/$1 [NC,R=301,L]
RewriteCond %{HTTP:Host} !^www\.yourdomain\.com$
RewriteCond %{HTTP:Host} ^(.+)\.yourdomain\.com$
RewriteRule (.*) http://mydomain.com/%1/$1 [NC,R=301,L]
Regards
Re: URL ReWrite SubDomains
Actually I meant "yourdomain" could be any other domain
So, anysubdomain will be redirected to mydomain.com/anysubdomain
anyotherdomain.anyextention will be redirected to mydomain.com/anyotherdomain-anyextention
Thank you
So, anysubdomain will be redirected to mydomain.com/anysubdomain
anyotherdomain.anyextention will be redirected to mydomain.com/anyotherdomain-anyextention
Thank you
- HeliconAndrew
-
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: URL ReWrite SubDomains
Would you shed some light here? How many sites do you have to redirect from? Maybe a mapfile is better idea.
Regards
Regards
Re: URL ReWrite SubDomains
We provide domain web hosting (Mapfile is not an option)
We would like to rewrite a URL such as
abc.tv to mydomain.com/abc-tv
the domain name and extension are variables
and
abc.mydomain.com to mydomain.com/abc
We would like to rewrite a URL such as
abc.tv to mydomain.com/abc-tv
the domain name and extension are variables
and
abc.mydomain.com to mydomain.com/abc
- HeliconAndrew
-
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: URL ReWrite SubDomains
In this case lets try:
- Code: Select all
RewriteCond %{HTTP:Host} !^www\.mydomain\.com$ [NC]
RewriteCond %{HTTP:Host} ^(.+)mydomain\.com$
RewriteRule (.*) http://mydomain.com/%1 [NC,R=301,L]
RewriteCond %{HTTP:Host} !^(?:www\.)?mydomain\.com$ [NC]
RewriteCond %{HTTP:Host} ^(?:www\.)?([^.]+)\.([^.]+)$
RewriteRule (.*) http://mydomain.com/%1-%2 [NC,R=301,L]
Re: URL ReWrite SubDomains
I tried the code but it did not do what I am looking for
1- the browser URL changes to mydomain.com/abc-tv (similar to redirect). I would like to keep the URL the same (abc.tv) but IIS serves the new URL (mydomain.com/abc-tv). The redirect should be hidden from the user
2- Also, the code does not pass/keep the subfolder and parameters. For example, for http://www.abc.tv/mydir/default.aspx?id=2, IIS should serves http://www.mydomain.com/abc-tv/mydir/default.aspx?id=2
Thank you
1- the browser URL changes to mydomain.com/abc-tv (similar to redirect). I would like to keep the URL the same (abc.tv) but IIS serves the new URL (mydomain.com/abc-tv). The redirect should be hidden from the user
2- Also, the code does not pass/keep the subfolder and parameters. For example, for http://www.abc.tv/mydir/default.aspx?id=2, IIS should serves http://www.mydomain.com/abc-tv/mydir/default.aspx?id=2
Thank you
- HeliconAndrew
-
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: URL ReWrite SubDomains
1. In this case use [P] instead of [R=301].
2. USe:
2. USe:
- Code: Select all
RewriteCond %{HTTP:Host} !^www\.mydomain\.com$ [NC]
RewriteCond %{HTTP:Host} ^(.+)mydomain\.com$
RewriteRule (.*) http://mydomain.com/%1/$1 [NC,P,L]
RewriteCond %{HTTP:Host} !^(?:www\.)?mydomain\.com$ [NC]
RewriteCond %{HTTP:Host} ^(?:www\.)?([^.]+)\.([^.]+)$
RewriteRule (.*) http://mydomain.com/%1-%2/$1 [NC,P,L]
Re: URL ReWrite SubDomains
Sorry to post a reply to an existing thread but my case is very similar.
I already have an existing rule
RewriteCond %{HTTP_HOST} !^www\.mysite.com
RewriteCond %{HTTP_HOST} ^(.+).mysite.com
RewriteRule ^([^/]*)$ http://mysite.com/?id=%1 [P,L]
I basically need to get the subdomain as a parameter for every page requested, i will process the id on the top of every page so the above rules works fine only for the root, but it is not grabbing anything after the .com
for example firefox.mysite.com/auth/admin/login.aspx
it should be processed in mysite.com/admin/login.aspx
1) How can I modify the rule to grab the pages after the .com?
2) if the subdomain is empty or starts with www|ftp|mail.mysite.com redirect to http://www.mastersite.com
Can you please help!? thanks
I already have an existing rule
RewriteCond %{HTTP_HOST} !^www\.mysite.com
RewriteCond %{HTTP_HOST} ^(.+).mysite.com
RewriteRule ^([^/]*)$ http://mysite.com/?id=%1 [P,L]
I basically need to get the subdomain as a parameter for every page requested, i will process the id on the top of every page so the above rules works fine only for the root, but it is not grabbing anything after the .com
for example firefox.mysite.com/auth/admin/login.aspx
it should be processed in mysite.com/admin/login.aspx
1) How can I modify the rule to grab the pages after the .com?
2) if the subdomain is empty or starts with www|ftp|mail.mysite.com redirect to http://www.mastersite.com
Can you please help!? thanks
- HeliconAndrew
-
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: URL ReWrite SubDomains
Try:
RewriteCond %{HTTP_HOST} !^(?:www|ftp|mail)\.mysite.com
RewriteCond %{HTTP_HOST} ^(.+).mysite.com
RewriteRule ^([^/]*)$ http://mysite.com/%1/$1 [P,L]
To debug, I'd suggest using R=301 instewad of P-flag. In this case URL would change and you'd actually see the landing URL.
Regards
RewriteCond %{HTTP_HOST} !^(?:www|ftp|mail)\.mysite.com
RewriteCond %{HTTP_HOST} ^(.+).mysite.com
RewriteRule ^([^/]*)$ http://mysite.com/%1/$1 [P,L]
To debug, I'd suggest using R=301 instewad of P-flag. In this case URL would change and you'd actually see the landing URL.
Regards
Re: URL ReWrite SubDomains
Hi Andrew thanks for your reply, rule doesn't work as I expected.
I need to be able to pass control to whatever page they are trying to hit
for example if they hit http://helicon.mysite.com/auth/login.asxp
I need the rule to hit http://mysite.com/auth/login.aspx?id=helicon
Note:* i dont need to add the subdomain to the url just as a parameter.
The below rule works well only if I hit the root
Please advise.
I need to be able to pass control to whatever page they are trying to hit
for example if they hit http://helicon.mysite.com/auth/login.asxp
I need the rule to hit http://mysite.com/auth/login.aspx?id=helicon
Note:* i dont need to add the subdomain to the url just as a parameter.
The below rule works well only if I hit the root
- Code: Select all
RewriteCond %{HTTP_HOST} !^(?:www|ftp|mail)\.mysite.com
RewriteCond %{HTTP_HOST} ^(.+).mysite.com
RewriteRule ^([^/]*)$ http://mysite.com/$1?id=%1 [P,L]
Please advise.
- HeliconAndrew
-
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: URL ReWrite SubDomains
In this case you'll end up with
either
or
either
- Code: Select all
RewriteCond %{HTTP_HOST} !^(?:www|ftp|mail)\.mysite.com
RewriteCond %{HTTP_HOST} ^(.+).mysite.com
RewriteRule ^(.*)$ http://mysite.com/$1?id=%1 [P,L]
or
- Code: Select all
RewriteCond %{HTTP_HOST} !^(?:www|ftp|mail)\.mysite.com
RewriteCond %{HTTP_HOST} ^(.+).mysite.com
RewriteRule ^(.*)$ http://mysite.com$1?id=%1 [P,L]
Re: URL ReWrite SubDomains
Hi Andrew, Sorry but we need your help one more time.
We have the following rule:
Which works fine, if someone hits http://subdomain.mysite.com
it gets the subdomain as a parameter = http://mysite.com/id=subdomain.
However any existing querystring is being ignored.
for example if I hit
http://subdomain.mysite.com/order.aspx?cart=abc
I never get the cart value, the Querystring is gone. I only get the id=subdomain.
Does it make sense?
Please advise!
We have the following rule:
- Code: Select all
RewriteCond %{HTTP_HOST} !^(?:www|ftp|mail)\.mysite.com
RewriteCond %{HTTP_HOST} ^(.+).mysite.com
RewriteRule ^(.*)$ http://mysite.com/$1?id=%1 [P,L]
Which works fine, if someone hits http://subdomain.mysite.com
it gets the subdomain as a parameter = http://mysite.com/id=subdomain.
However any existing querystring is being ignored.
for example if I hit
http://subdomain.mysite.com/order.aspx?cart=abc
I never get the cart value, the Querystring is gone. I only get the id=subdomain.
Does it make sense?
Please advise!
13 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 15 guests