WEB .htaccess help again?

Discussion in 'OT Technology' started by White Stormy, Sep 13, 2008.

  1. White Stormy

    White Stormy Take that, subspace!

    Joined:
    Sep 17, 2002
    Messages:
    85,489
    Likes Received:
    70
    Location:
    Sparkopolis
    I want to rewrite requests to my main domain to a file called "list.html"
    but requests to subdomains or subfolders need to not be effected.

    so example.com is rewritten to "list.html"
    but sub.example.com acts as normal
    and example.com/sub/ acts as normal

    I'm sure you can do this.. and I bet it's really easy.. but what I thought it would be didn't work :(

    I tried..
    RewriteRule ^/$ /list.html [L]

    but no dice :(
     
  2. Ender0910

    Ender0910 woot!

    Joined:
    Jun 1, 2004
    Messages:
    3,039
    Likes Received:
    0
    Location:
    Redmond/Bay Area
  3. White Stormy

    White Stormy Take that, subspace!

    Joined:
    Sep 17, 2002
    Messages:
    85,489
    Likes Received:
    70
    Location:
    Sparkopolis
    can't do that. the subdomains don't actually exist.. they're just symlinks pointing to the main folder. the default file has to be an index.php for all of the subdomains to function.. I just want to rewrite when the domain itself is accessed so I can serve out an html file for that instead of complicating the index.php.. especially since the index.php may change in the future.
     
  4. White Stormy

    White Stormy Take that, subspace!

    Joined:
    Sep 17, 2002
    Messages:
    85,489
    Likes Received:
    70
    Location:
    Sparkopolis
  5. pkr

    pkr Guest

    In for answer.
     
  6. Deviance

    Deviance Can't you smell that smell? OT Supporter

    Joined:
    Jul 10, 2007
    Messages:
    4,988
    Likes Received:
    12
    Location:
    Rocky Mountain High
  7. White Stormy

    White Stormy Take that, subspace!

    Joined:
    Sep 17, 2002
    Messages:
    85,489
    Likes Received:
    70
    Location:
    Sparkopolis
    I have something in .htaccess already to remove the www. and force "domain.com"
     
  8. whup

    whup I wish you had children and.. so that I could step

    Joined:
    Feb 12, 2007
    Messages:
    1,603
    Likes Received:
    0
    RewriteCond %{HTTP_HOST} example\.com [NC]
    RewriteRule ^(.*)$ list.html [L]

    That work for you? Did you want any request to example.com to go to list.html, or just the default document?
     
  9. White Stormy

    White Stormy Take that, subspace!

    Joined:
    Sep 17, 2002
    Messages:
    85,489
    Likes Received:
    70
    Location:
    Sparkopolis
    I was thinking about maybe later making other requests to it search all the subdomains for matching content.. but for now if everything goes to the list.html that would be awesome.

    trying it now
     
  10. White Stormy

    White Stormy Take that, subspace!

    Joined:
    Sep 17, 2002
    Messages:
    85,489
    Likes Received:
    70
    Location:
    Sparkopolis
    that forwards all the subdomains to list.html as well

    but added a ^ to the condition and then it worked.. I wasn't sure you could add operators and stuff to a condition.. guess you can :)

    thanks
     
  11. White Stormy

    White Stormy Take that, subspace!

    Joined:
    Sep 17, 2002
    Messages:
    85,489
    Likes Received:
    70
    Location:
    Sparkopolis
    that forwards any URL with the base example.com to list.html, and I still can't figure out how to make it only rewrite just the main directory and leave other links alone. I realized earlier that I can't resolve files that do exist inside the main directory, cause this is rewriting their links to the list.html :(
     
  12. whup

    whup I wish you had children and.. so that I could step

    Joined:
    Feb 12, 2007
    Messages:
    1,603
    Likes Received:
    0
    RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
    RewriteRule ^\/+$ list.html [L]

    Does that work for you?

    Also, did you want www.example.com to go to list.html as well, or just example.com?
     
  13. White Stormy

    White Stormy Take that, subspace!

    Joined:
    Sep 17, 2002
    Messages:
    85,489
    Likes Received:
    70
    Location:
    Sparkopolis
    doesn't work :(

    I do want www. to forward as well, but I already have a rule in place forcing the user not to use it, so that should take care of it
     
  14. White Stormy

    White Stormy Take that, subspace!

    Joined:
    Sep 17, 2002
    Messages:
    85,489
    Likes Received:
    70
    Location:
    Sparkopolis
    this is the rewrite part of my .htaccess right now. I've tried it both with and without the rewritebase, and it didn't make a difference.
    Code:
    # Various rewrite rules.
    <IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteBase /
      
      # To redirect all main domain visitors to the directory listing.
      RewriteCond %{HTTP_HOST} ^halefx\.com$ [NC]
      RewriteRule ^\/+$ list.html [L]
      
      # To redirect all users to access the site WITHOUT the 'www.' prefix.
      RewriteCond %{HTTP_HOST} ^www\.halefx\.com$ [NC]
      RewriteRule ^(.*)$ http://halefx.com/$1 [L,R=301]
      
      # Short links for a Drupal sites' files
      RewriteCond %{HTTP_HOST} ^(.+)\.halefx\.com$ [NC]
      RewriteRule ^files/(.+)$ http://halefx.com/sites/%{HTTP_HOST}/files/$1 [L]
      
      # Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_URI} !=/favicon.ico
      RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
    </IfModule>
    
    
     
  15. whup

    whup I wish you had children and.. so that I could step

    Joined:
    Feb 12, 2007
    Messages:
    1,603
    Likes Received:
    0
    Meh why am I trying to escape the forward slash!

    Code:
    RewriteRule ^/+$ list.html [L]
    Sorry, my fault as I'm not testing any of this myself. This should work (but I said that last time).

    If it doesn't work please tell me what exactly isn't working
     
  16. White Stormy

    White Stormy Take that, subspace!

    Joined:
    Sep 17, 2002
    Messages:
    85,489
    Likes Received:
    70
    Location:
    Sparkopolis
    still doesn't work. it just goes to the index.php like it would normally :hs:

    I want just http://halefx.com/ and http://www.halefx.com/ to go to list.html
     
  17. noon

    noon get high and teach me how to listen

    Joined:
    May 4, 2002
    Messages:
    3,384
    Likes Received:
    0
    Location:
    Lawrence, KS
    instead of rewriting for /, you may try rewriting for index.php
     
  18. White Stormy

    White Stormy Take that, subspace!

    Joined:
    Sep 17, 2002
    Messages:
    85,489
    Likes Received:
    70
    Location:
    Sparkopolis
    still doesn't work :hs:

    it works for every URL at the main domain EXCEPT the main domain itself.. same result as rewriting ^(.*)$ :hs:
     
  19. whup

    whup I wish you had children and.. so that I could step

    Joined:
    Feb 12, 2007
    Messages:
    1,603
    Likes Received:
    0
    RewriteRule ^/*$ list.html [L]

    And if that doesn't work then add:

    RewriteRule ^index.php$ list.html [L]

    And if that doesn't, see if you need the slash before:

    RewriteRule ^/index.php$ list.html [L]

    Still having probelms, turn on the rewrite log to see exactly what's happening: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritelog
     
  20. White Stormy

    White Stormy Take that, subspace!

    Joined:
    Sep 17, 2002
    Messages:
    85,489
    Likes Received:
    70
    Location:
    Sparkopolis
    :bowdown: that one worked perfectly.

    http://halefx.com/

    now I just gotta make the list.html look halfway decent
     

Share This Page