Rewrite Subdomain to Script

Hello:

I am trying to map the subdomain my.domain.com to a single script really located at domain.com/my.php.

I’ve tried the following combinations of code, and none have worked:


RewriteCond %{HTTP_HOST} ^my\\.domain\\.com$
RewriteRule ^(.*)$ my.php?query=$1 [P]

RewriteCond %{HTTP_HOST} ^[www\\.]*my.domain.com [NC]
RewriteRule ^(.*) my.php?query=$1  [L]

Any ideas? Thanks in advanced.

For future reference, it’s helpful if you explain in what way it didn’t work. Are you getting a different page? Are you getting a 500 error? Is nothing happening at all?

For the time being, I’m going to guess that you’re getting a 500 error, and the reason may be because you’re stuck in an infinite loop. The reason is because the URL my.php also matches the pattern FONT=Courier New[/FONT]. You’ll probably need a rewrite condition. For example, you can check that the pattern you capture isn’t my.php.

RewriteCond %{HTTP_HOST} ^my\.domain\.com$
RewriteCond $1 !=my.php
RewriteRule ^(.*)$ my.php?query=$1

Sorry about that! I forgot to mention the error and how it wasn’t working. I receive a ERR_NAME_NOT_RESOLVED error code when browsing in Google Chrome (DNS error). To me, this must mean that the request is not being any way rewritten and that the browser is looking for an A record for the subdomain.

I’ve tried your newly updated code (to ensure that there’s not an infinite loop) and the code is not working (same error: DNS look up failed).

If it’s of any further help, I am running a cPanel server (dunno if this makes things quirky).

Thanks again for your help! I appreciate it.