Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-28-2005, 05:30 AM   PM User | #1
Coastal Web
Regular Coder

 
Coastal Web's Avatar
 
Join Date: Oct 2004
Posts: 225
Thanks: 12
Thanked 3 Times in 3 Posts
Coastal Web is an unknown quantity at this point
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
Coastal Web is offline   Reply With Quote
Old 11-28-2005, 04:30 PM   PM User | #2
schleppel
Regular Coder

 
Join Date: Oct 2004
Posts: 330
Thanks: 0
Thanked 13 Times in 13 Posts
schleppel is an unknown quantity at this point
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.
schleppel is offline   Reply With Quote
Old 11-28-2005, 11:57 PM   PM User | #3
Coastal Web
Regular Coder

 
Coastal Web's Avatar
 
Join Date: Oct 2004
Posts: 225
Thanks: 12
Thanked 3 Times in 3 Posts
Coastal Web is an unknown quantity at this point
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
Coastal Web is offline   Reply With Quote
Old 11-29-2005, 12:33 AM   PM User | #4
plasterx
Regular Coder

 
Join Date: Oct 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
plasterx is an unknown quantity at this point
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.
plasterx is offline   Reply With Quote
Old 11-29-2005, 03:36 PM   PM User | #5
schleppel
Regular Coder

 
Join Date: Oct 2004
Posts: 330
Thanks: 0
Thanked 13 Times in 13 Posts
schleppel is an unknown quantity at this point
It shouldn't redirect (and change the address bar), mod_rewrite does it internally, unless the [R] flag is used.
schleppel is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:47 PM.


Advertisement
Log in to turn off these ads.