Forum Moderators: phranque

Message Too Old, No Replies

Subdomain Redirect with parameter

         

abm24

11:13 am on Sep 27, 2009 (gmt 0)

10+ Year Member



Hi,

Let's say that I own the domain: xyz.com.

I want to redirect from a fake subdomain, such as:
[mywebsite.xyz.com...] to [xyz.com...]
[anotherexample123.xyz.com...] to [xyz.com...]

I also want it to ignore the subdomains:
www , cdn , uploaded
as they're my website reserved subdomains.

How do I do that with htaccess file?

thanks!

jdMorgan

3:05 pm on Sep 27, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This subject has been much-discussed here. I commend the WebmasterWorld "Site search" feature to you. Having reviewed those previous threads, please post your best-effort code and test results should you need further assistance. Our Apache Forum Charter (see link above) may be useful to you in getting the most from this forum.

Thanks,
Jim

abm24

1:20 am on Sep 28, 2009 (gmt 0)

10+ Year Member



As a matter of fact I did, but I can't make it ignore my reserved subdomains.

Here's what I got so far:
RewriteCond %{HTTP_HOST} ([^.]+)\.example.com [NC]
RewriteRule ^(.*) http://example.com/resolver.php?id=%1 [P]

jdMorgan

1:24 pm on Sep 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Add a RewriteCond at the top to exclude your subdomains, start-anchor your second RewriteCond's pattern, anchor your RewriteRule pattern, use an internal rewrite instead of a proxy-throughput (if possible), and always use the [L] flag unless you know why you don't want to. Do not use [NC] on hostnames, as they should always be lowercase, and should be redirected (in a separate rule) to force lowercase if they are not.

RewriteCond %{HTTP_HOST} !^(www¦cdn¦uploaded)\.example\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.example.com
RewriteRule ^(.*)$ /resolver.php?id=%1 [L]

Important: Replace the broken pipe "¦" characters with solid pipe characters before use; Posting on this forum modifies the pipe characters.

Jim

abm24

4:22 pm on Sep 28, 2009 (gmt 0)

10+ Year Member



Thanks Jim!