...

View Full Version : htaccess mod rewrite explanation pls



Coastal Web
11-28-2005, 05:30 AM
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:


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

schleppel
11-28-2005, 04:30 PM
This is i hope a full explaination:

# 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.

Coastal Web
11-28-2005, 11:57 PM
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

plasterx
11-29-2005, 12:33 AM
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.

schleppel
11-29-2005, 03:36 PM
It shouldn't redirect (and change the address bar), mod_rewrite does it internally, unless the [R] flag is used.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum