Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder Coastal Web's Avatar
    Join Date
    Oct 2004
    Posts
    225
    Thanks
    12
    Thanked 3 Times in 3 Posts

    htaccess mod rewrite explanation pls

    Hello folks, l'm attempting to point several different domains at my current website, just direct them to different sub directories depending on what domain name they typed in to come to my site...

    Now l was able to find the following snip on google:

    Code:
    RewriteEngine On 
    Options +FollowSymlinks 
    RewriteBase / 
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d 
    RewriteRule ^/*(internet/)?(.*[^/])$ http://%{HTTP_HOST}/$2/ [R=301,L] 
    RewriteCond %{HTTP_HOST} internet.com 
    RewriteCond %{REQUEST_URl} !internet/ 
    RewriteRule ^(.*)$ internet/$1 [L]
    That l *think* is what l'm looking for, but l don't quite understand everything that's going on here. If anyone would be willing tho break down and explain each of the htaccess code above l would greatly appreciate it!

    Samantha Gram

  • #2
    Regular Coder
    Join Date
    Oct 2004
    Posts
    376
    Thanks
    0
    Thanked 25 Times in 25 Posts
    This is i hope a full explaination:
    Code:
    # Turn on mod_rewrite
    RewriteEngine On
    
    # make apache follow symlinks
    Options +FollowSymlinks
    
    # set the rules to start at /
    RewriteBase /
    
    # check if the requested directory exists
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
    
    # capture anything after /internet/ and redirect it to current_domain.tld/capured_bit
    # eg http://somedomain.com/internet/fire becomes http://somedomain.com/fire
    RewriteRule ^/*(internet/)?(.*[^/])$ http://%{HTTP_HOST}/$2/ [R=301,L]
    
    # if domain contains internet.com
    RewriteCond %{HTTP_HOST} internet.com
    
    # and requested URI does not contain internet/
    RewriteCond %{REQUEST_URI} !internet/
    
    # redirect to internet/whatever
    RewriteRule ^(.*)$ internet/$1 [L]
    Note the red i in the code seems to have been an L, which is incorrect.

    If it's not what you want could you provide a fuller explaination of what you want.

  • #3
    Regular Coder Coastal Web's Avatar
    Join Date
    Oct 2004
    Posts
    225
    Thanks
    12
    Thanked 3 Times in 3 Posts

    Thumbs up

    Nope that's exactly what l was looking for, thank you for the help, one more question..

    Lets say l have two domain names:
    name1.com
    and name2.com

    name1.com is my main domain name... and l use this code you've just helped me with to redirect people visiting name2.com to a sub directory called "/name2files".

    So when someone visits www.name2.com, they'll actually be seeing:
    http://www.name1.com/name2files

    My question is, will the address bar read:
    www.name2.com?

    or will it read: http://www.name1.com/name2files?

    Thanks for your help with this schleppel.

    Samantha Gram

  • #4
    Regular Coder
    Join Date
    Oct 2005
    Posts
    140
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if i'm not wrong it'll read the 2nd one - name1.com/name2files. that's the experience i had with quite a few webbys. My guess is it has to do with the url redirect script.

  • #5
    Regular Coder
    Join Date
    Oct 2004
    Posts
    376
    Thanks
    0
    Thanked 25 Times in 25 Posts
    It shouldn't redirect (and change the address bar), mod_rewrite does it internally, unless the [R] flag is used.


  •  

    Posting Permissions

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