SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    pie??? PIE!!!! rsdl's Avatar
    Join Date
    May 2001
    Location
    Vancouver, BC Canada
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    more mod_rewrite woes

    i'm trying to configure subdomains with mod_rewrite
    this is what i have in my .htaccess

    Code:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^([^.]+)\.dfexchange\.ca$ [NC]
    RewriteCond %1 !^www$ [NC]
    RewriteRule ^$ /user.php?username=%1 [L]
    and i've also enabled rewriteLogging and here's a snippet:

    Code:
    ...RewriteCond: input='dfexchange.ca' pattern='^([^.]+)\.dfexchange\.ca$' => not-matched
    anyone know what i'm doing wrong?
    thanks in advance

    -rey

  2. #2
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    > anyone know what i'm doing wrong?
    Yes, in fact
    ([^.]+)\.dfexchange\.ca
    means
    somethingobbligatory.dfexchange.ca

    That's fine because somethingobbligatory is the username...

    So in my opinion I'd not change your rules because dfexchange.ca is not an user!

    Eventually I can show this alternative method just to play with regular expressions, but that's not necessary but I'll show

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^(([^.]+)\.)?dfexchange\.ca$ [NC]
    RewriteCond %2 !^(www)?$ [NC]
    RewriteRule ^$ /user.php?username=%2 [L]

    >RewriteCond %{HTTP_HOST} ^(([^.]+)\.)?dfexchange\.ca$ [NC]
    www.example.net
    %1 will be www.
    %2 will be www

    example.net
    %1 will be <empty>
    %2 will be <empty>

    >RewriteCond %2 !^(www)?$ [NC]
    What's !^(www)?$ ?!?
    Means: if ((%2 != "www") AND (%2 != ""))



    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03

  3. #3
    Don't eat yellow snow spaceman's Avatar
    Join Date
    Mar 2001
    Location
    Melbourne, Australia
    Posts
    1,039
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Pippo,

    Thanks to your work here, I concoted this mod-rewrite:

    Code:
    RewriteEngine on
       RewriteCond %{HTTP_HOST} ^(([^.]+)\.)?domain\.com$ [NC]
       RewriteCond %2 !^(www)?$ [NC]
       RewriteRule ^$ /generic/ [L]
    Result:
    - http://www.domain.com is left untouched
    - http://*.domain.com is rewritten to subdomain/subfolder www.domain.com/generic/ (where * is a wildcard subdomain name).

    This is great. This is exactly what I had intended.

    But just one extra bit of help with regular expressions if I may... I'd like either
    http://*.domain.com
    OR
    http://www.*.domain.com
    to be rewritten to
    www.domain.com/generic/

    Can u help? Here's hoping! It's a regular expression thing...

    Thanks v. much.

    ------
    Note: I had to first establish a wildcard subdomain entry for this domain. I did this by
    1. Adding a CNAME record to the zone file for domain.com, exactly the same as www but * instead.
    2. Adding to httpd.conf: ServerAlias *.domain.com
    3. Restarting bind/named and httpd/apache
    Last edited by spaceman; Dec 7, 2003 at 18:57.
    Web Design Perth Melbourne .:. Itomic Business Website Solutions
    Drupal Experts .:. Drupalise

  4. #4
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yup ,
    it's a regex issue.

    Try this:
    Code:
    RewriteEngine on
      RewriteCond %{HTTP_HOST} ^(www\.)?(([^.]+)\.)?example\.net$ [NC]
      RewriteCond %3 !^(www)?$ [NC]
      RewriteRule ^$ /generic/ [L]

    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03

  5. #5
    Don't eat yellow snow spaceman's Avatar
    Join Date
    Mar 2001
    Location
    Melbourne, Australia
    Posts
    1,039
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Pippo.

    Not sure if that's working yet, because something else really weird is happening (gotta love mod_rewrite!)

    I'm just randomly making up some subdomain names (without leading www.), all of which are supposed to be rewritten to www.domain.com/generic, and some work, and some don't (page cannot be found), with seemingly no rhyme or reason why or why not.

    For example:
    http://blah.domain.com = works!
    but
    http://blahblah.domain.com = does not work!

    Like I said, I'm entering lots of these, and can't see any pattern whatsoever for success/failure. Is this bizarre behaviour a characteristic of mod-rewrite or me?!? :-)

    More results:
    http://blaa.domain.com - no :-(
    http://blab.domain.com - no :-(
    http://blac.domain.com - no :-(
    http://blad.domain.com - yes!
    http://blae.domain.com - yes!
    http://blaf.domain.com - yes!
    http://blag.domain.com - yes!
    http://blah.domain.com - yes!
    http://blai.domain.com - no :-(
    http://blaj.domain.com - no :-(
    http://blak.domain.com - no :-(

    So there's a pattern, but I'm seriously scratching my head now... Off to bed before my brain implodes (it's late Sunday here, wish I could say I've been drinking) :-)
    Last edited by spaceman; Dec 7, 2003 at 18:56.
    Web Design Perth Melbourne .:. Itomic Business Website Solutions
    Drupal Experts .:. Drupalise

  6. #6
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you are talking about the squashclubs.com domain.
    Well I saw that some subdomains work, others not.
    The problem is not mod_rewrite because the problem is one stage before, it's a DNS issue.
    Basically the browser cannot found the IP address when you type some type of subdomains.
    In fact doing a nslookup I can match some subdomains, others not.

    I'm not a DNS expert, maybe the problem is due to some DNS caching.
    So maybe you have to wait 24/48 hours to let your wildcard domains to propagate.
    Mine is an hypothesis, though ;-)


    :-)
    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03

  7. #7
    Don't eat yellow snow spaceman's Avatar
    Join Date
    Mar 2001
    Location
    Melbourne, Australia
    Posts
    1,039
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're absolutely right - domain cache/propagation issue! I never thought a wildcard subdomain entry would propagate so haphazardly :-)

    Thanks again - the www works too - you're a legend!
    Web Design Perth Melbourne .:. Itomic Business Website Solutions
    Drupal Experts .:. Drupalise


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
  •