Forum Moderators: phranque
When I go to e.g. [example.mysite.com...] it takes the content from [mysite.com...] but I want to take it from [mysite.com...]
My .htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^www\. [NC]
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI} ^([^.]+)\.mysite\.com(:80)?<>/([^/]*) [NC]
RewriteCond %1<>%3!^(.*)<>\1$ [NC]
RewriteRule ^(.*) /%1/$1 [L]
I've tried to change the last line, "RewriteRule ^(.*) /%1/$1 [L]" to "RewriteRule ^(.*) /sub/%1/$1 [L]", which I hoped would solve my problem, but it doesn't.
Hope somebody knows what to do. Thank you in advance.
Regards,
wanze
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^www\. [NC]
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI} ^([^.]+)\.mysite\.com(:80)?<>/sub/([^/]*) [NC]
RewriteCond %1<>%3!^(.*)<>\1$ [NC]
RewriteRule ^(.*) /sub/%1/$1 [L]
But when I e.g. go to [example.mysite.com...] it just says: "You don't have permission to access / on this server"
I simply want [mysite.com...] and [mysite.com...] to take the content from [mysite.com...] so it actually is impossible to access the REAL root(http://www.mysite.com/).
If the only subdomain you want to support is "www", then a much simpler solution can be used. Something like this in your Web root .htaccess file should do it:
# Force www canonical hostname
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule (.*) http://www.example.com [R=301,L]
#
# Rewrite all requests to www subdirectory, but prevent rewrite looping
RewriteCond $1 !^www/
RewriteRule (.*) /www/$1 [L]
#
# Forbid direct-request access to /www subfolder
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /www/
RewriteRule .* - [F]
Next, we rewrite any request for your Web root directory to the /www subdirectory.
However, you then have the problem that someone may link directly to "www.example.com/www/", which is an unnecessarily long, ugly URL, and which presents a duplicate-content problem, since the same pages will also appear at "www.example.com/". So the last rule forbids any external direct request for the /www subdirectory URL, but does not affect the internal rewrite.
If your server seems to be ignoring the rewrite to the subdirectory, then you may need to set RewriteOptions inherit in .htaccess in the /www subdirectory.
Jim
So, I'll explain it again.
When I log in on my FTP, I'm in my root.
If I upload hello.txt to / on the FTP, it'll be at [mysite.com...] and [mysite.com...]
I want everything in subdirectories.
e.g:
Thanks for your time! :)
WWW sucks - [no-org...]
_____
EDIT:
I didn't mention it, because I thought you just would make something which would do the same as the WWW-thing did, so it wouldn't be as difficult to understand.
Did the original code work OK other than your specific reported problem? (I'm trying to make sure you've got POSIX 1003.2 support before going on, since this will make a major difference in what might need to be done).
For now, and if you still hate www after considering the post I cited, simply reverse the domain names in the first rule:
# Force www canonical hostname
RewriteCond %{HTTP_HOST} ^www\.example\.com
RewriteRule (.*) http://example.com [R=301,L]
We'll take care of the rest after verifying that your server will support the POSIX 1003.2 atomic back-reference (the "\1$" in the original code) which is required to prevent looping on arbitrary subdomain to subdirectory rewrites.
Jim
jdMorgan has left me. :(
RewriteEngine On
#
# external redirect from www.example.com to example.com
RewriteCond %{HTTP_HOST} ^www\.example\.com
RewriteRule ^(.*) http://example.com/$1 [R=301,L]
#
# Host starts with example.com (without any subdomain)
RewriteCond %{HTTP_HOST} ^example\.com
# prevent looping
RewriteCond $1 !^www/
# internal redirect to /www/ (example.com goes into the www folder)
RewriteRule ^(.*) /www/$1 [L]
#
# host is xyz.example.com (this will not affect www.example.com, because an
# external redirect took place above to example.com
# this will not match for www.sub.example.com
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI} ^([^.]+)\.example\.com(:80)?<>/([^/]*) [NC]
# prevent looping if we're already in /xyz/
RewriteCond %1<>%3 !^(.*)<>\1$ [NC]
RewriteRule ^(.*) /%1/$1 [L]