(htaccess) Rewriting subdomains

Discussion in 'Site & Server Administration' started by scoutz, Aug 9, 2008.

  1. #1
    I want to do the following:

    user.domain.com/gallery/galleryname.html ($user and $galleryname)

    I currently already have the following rewrite rule to rewrite the subdomains but I have no idea on how to rewrite the /gallery/gallername.html part.

    
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteCond %{HTTP_HOST} ([^.]+)\.domain\.com [NC]
    RewriteRule ^(.*)$ /path/index.php?user=%1 [QSA,L]
    
    Code (markup):

     
    scoutz, Aug 9, 2008 IP
  2. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Something like ...

    
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteCond %{HTTP_HOST} ([^.]+)\.domain\.com [NC]
    RewriteRule gallery/(.*?)\.html$ /path/index.php?user=%1&galleryname=$1 [QSA,L]
    
    Code (markup):
    Jay
     
    jayshah, Aug 9, 2008 IP
  3. scoutz

    scoutz Well-Known Member

    Messages:
    275
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #3
    My first post wasn't that clear sorry what I meant is

    username.domain.com -> profile.php?user=$1
    username.domain.com/gallery/galleryname.html -> gallery.php?user=$1&folder=$2

    edit:

    Ok got it working but it can probably be done a lot easier I think here's how I did it,


    RewriteCond %{HTTP_HOST} !^www\.
    RewriteCond %{HTTP_HOST} ([^.]+)\.domain\.net$ [NC]
    RewriteCond %{REQUEST_URI} !^/gallery/([^.]+)\.html$ [NC]
    RewriteRule ^(.*)? profile.php&username=%1 [QSA,L]
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteCond %{REQUEST_URI} ^/gallery/(.*)\.html$ [NC]
    RewriteCond %{HTTP_HOST} ([^.]+)\.domain\.net$ [NC]
    RewriteRule ^(gallery/(.+)\.html?)$ gallery.php?username=%1&folder=$2 [QSA,L]
     
    scoutz, Aug 9, 2008 IP