SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool 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:

    Code:
    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.

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,148
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Panduola View Post
    I've tried the following combinations of code, and none have worked:
    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 (.*). 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
    "First make it work. Then make it better."

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •