Click to See Complete Forum and Search --> : htaccess forwarding


cybercampbell
06-15-2006, 05:12 PM
Hi all

So this is my delima..... I'm setting up a community site and this is how the URLs will look:

either:

http://www.mydomain.com/cybercampbell
http://mydomain.com/cybercampbell

or

http://cybercampbell.mydomain.com

And this is where they need to end up on the server:

htdocs/users/c/cy/cybercampbell

so....the user "trevor" would be:

htdocs/users/t/tr/trevor

I need to do this using the .htaccess file

Any ideas?

Cheers
Cybercampbell

Scleppel
06-15-2006, 07:15 PM
either:

http://www.mydomain.com/cybercampbell
http://mydomain.com/cybercampbell

or

http://cybercampbell.mydomain.com
You would like all those options? (The code below should support them all).

Will the subdomains will be pointed to the same document root as the main domain (/httpdocs)? That's probably the easiest way.

What happens when people go to cybercampbell.mydomain.com/some/stuff/here?

Try this:
Options +FollowSymLinks

RewriteEngine On

# if it's not www.DOMAIN or DOMAIN
RewriteCond %{HTTP_HOST} !^(www\.)?DOMAIN$ [NC]
# match abcd.DOMAIN -> /users/a/ab/abcd/
# %1 = abcd, %2 = ab, %3 = a
RewriteCond %{HTTP_HOST} ^(((.).).+)\.DOMAIN$ [NC]
RewriteRule ^$ /users/%3/%2/%1/ [L]


# if it's not a real file
RewriteCond %{SCRIPT_FILENAME} !-f
# and it's not a real directory
RewriteCond %{SCRIPT_FILENAME} !-d
# match /abcd/ -> /users/a/ab/abcd/
# $1 = abcd, $2 = ab, $3 = b
RewriteRule ^(((.).)[^/]+)/?$ /users/$3/$2/$1/ [L]
DOMAIN should be replaced with your domain. You should escape any "."s with a "\", eg. "google.com" becomes "google\.com".

cybercampbell
06-16-2006, 03:19 AM
What happens when people go to cybercampbell.mydomain.com/some/stuff/here?


That's a great point....can I fix that....none of the images in the site that use the full URL work now and none of the extentions of that directory.

Can this be fixed?

Cheers
cybercampbell

Scleppel
06-16-2006, 06:32 AM
none of the images in the site that use the full URL work now
Images with a URL such as "domain.com/images.jpg" don't work? Maybe this will work for you:
RewriteEngine On

# if it's a real file or
RewriteCond %{SCRIPT_FILENAME} -f [OR]
# a real directory
RewriteCond %{SCRIPT_FILENAME} -d
# do nothing
RewriteRule .* - [L]

# if it's not www.DOMAIN or DOMAIN
RewriteCond %{HTTP_HOST} !^(www\.)?DOMAIN$ [NC]
# match abcd.DOMAIN -> /users/a/ab/abcd/
# %1 = abcd, %2 = ab, %3 = a
RewriteCond %{HTTP_HOST} ^(((.).).+)\.DOMAIN$ [NC]
RewriteRule ^$ /users/%3/%2/%1/ [L]

# match /abcd/ -> /users/a/ab/abcd/
# $1 = abcd, $2 = ab, $3 = b
RewriteRule ^(((.).)[^/]+)/?$ /users/$3/$2/$1/ [L]

What are "extentions of that directory"? Do you mean /abcd/somestuff -> /a/ab/abcd/somestuff? If you do, replace both occurances of "1/" (on the RewriteRule lines) with "1%{REQUEST_URI}".

That's a great point
You have to decide what yoou would like do with it. You can leave it like it is now, and it'll give then the files as if they were at domain.com or www.domain.com, you can have it redirect the to domain.com or send a forbidden header or something.