Redirect Subdomains with URL to Query String
7 posts
• Page 1 of 1
Redirect Subdomains with URL to Query String
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
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
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Redirect Subdomains with URL to Query String
Please, provide direct examples of the URLs you'd like to accept and to redirect to.
Regards
Andrew
Regards
Andrew
Re: Redirect Subdomains with URL to Query String
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
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
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Redirect Subdomains with URL to Query String
Try using the following:
Regards
Andrew
- Code: Select all
RewriteCond %{HTTP_Host} [^.]+.thedomain.com/?$ [NC]
RewriteRule ^([^/]+)/([^/]+)/$ /url.asp?id=$1&page=$2 [NC,L]
Regards
Andrew
Re: Redirect Subdomains with URL to Query String
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
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
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Redirect Subdomains with URL to Query String
The best way to do is to create a separate rule for each scenario. It would be more reliable.
Regards
Andrew
Regards
Andrew
7 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 29 guests