Redirect Subdomains with URL to Query String

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 4
Joined: 15 Oct 2012, 13:05

Redirect Subdomains with URL to Query String

15 Oct 2012, 13:12

Hi there. I am trying to redirect a subdomain to a certain URL, which I have working fine. But now i cannot seem to get the next part working - the URL portion. I need to grab the URL portion and send it to the query string to look up on it. Here is a sample URL: http://mysubdomain.thedomain.com/123/something-here/

This is my code that is working for (http://mysubdomain.thedomain.com) only.

RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP:Host} ^(?:www.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://%2%3 [R=301,L]
RewriteCond %{HTTP_Host} ([^.]+).thedomain.com/?$ [NC]
RewriteRule (.*) /url.asp$1?d=%1 [NC,L]

Ultimately I need to have the "123" as the second item in the query string and "something-here" as the third.

Can anyone help me out? Seems like something simple, I have been hacking around with this for too long though!!

Thanks so much!!

Dennis

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Redirect Subdomains with URL to Query String

15 Oct 2012, 20:29

Please, provide direct examples of the URLs you'd like to accept and to redirect to.

Regards
Andrew

User avatar
Posts: 4
Joined: 15 Oct 2012, 13:05

Re: Redirect Subdomains with URL to Query String

16 Oct 2012, 10:11

Hi Andrew, here is a sample, sorry:

http://mysubdomain.thedomain.com/123/something-here/

should go to

/url.asp$1?d=%&id=123&page=something-here

I need to have access to "id" and "page" when I have access to the subdomain - all on the querystring.

Thanks!

Dennis

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Redirect Subdomains with URL to Query String

16 Oct 2012, 13:07

Try using the following:

Code: Select all
RewriteCond %{HTTP_Host} [^.]+.thedomain.com/?$ [NC]
RewriteRule ^([^/]+)/([^/]+)/$ /url.asp?id=$1&page=$2 [NC,L]


Regards
Andrew

User avatar
Posts: 4
Joined: 15 Oct 2012, 13:05

Re: Redirect Subdomains with URL to Query String

16 Oct 2012, 15:13

I got it to work with a couple slight tweaks:

RewriteCond %{HTTP_Host} ([^.]+).thedomain.com/?$ [NC]
RewriteRule ^([^/]+)/([^/]+)/$ /url.asp?d=%1&id=$1&page=$2 [NC,L]
RewriteCond %{HTTP_Host} ([^.]+).thedomain.com/?$ [NC]
RewriteRule (.*) /url.asp$1?d=%1 [NC,L]

I needed to add the second condition since if there was nothing passed in for the URL part (http://mysubdomain.thedomain.com), it would not work. If there is a way to build in the following URLs to one rule, that would be great!

http://mysubdomain.thedomain.com
http://mysubdomain.thedomain.com/123/
http://mysubdomain.thedomain.com/123/something-here/

THANK YOU!

Dennis

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Redirect Subdomains with URL to Query String

16 Oct 2012, 16:00

The best way to do is to create a separate rule for each scenario. It would be more reliable.

Regards
Andrew

User avatar
Posts: 4
Joined: 15 Oct 2012, 13:05

Re: Redirect Subdomains with URL to Query String

16 Oct 2012, 20:04

ok, thanks!

Dennis

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 29 guests