Forum Moderators: phranque

Message Too Old, No Replies

Sub domains redirected to sub directories?

an .htaccess issue

         

followgreg

11:17 pm on Aug 30, 2005 (gmt 0)

10+ Year Member



Hi,

I have a website on which I created some sub domains and each sub domain seems to be redirected to a subfolder of my main domain....which I don't want (for customers)

The hosting says it is because of my .htaccess file

RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
#RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

RewriteRule!\..{2,4}$ - [C]
RewriteCond %{REQUEST_URI}!^/.+/$
RewriteRule ^(.+)$ http://www.example.com/$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d

Someone else helped me doing the .htaccess so I'm no knowleadgeable about it at all, can someone help me figure out if this is really an .htaccess problem?

jd01

1:16 am on Aug 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RewriteRule!\..{2,4}$ - [C]
RewriteCond %{REQUEST_URI}!^/.+/$
RewriteRule ^(.+)$ http://www.example.com/$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d

The problem appears to be in this ruleset.

Rule 1: if the requested path does not end in a .(dot) followed by any character except the end of a line, complete the next rule:

Rule 2: if the requested path contains one or more characters, except the end of a line and does not begin with a / followed by one or more characters that are not the end of a line followed by a / at the end of the path - rewrite everyting to http://www.example.com/thecompletepath/

Unless there is more to the file, the final two conditions have no effect, they only impact the immediately following rule, and there is no rule.

So, any files on a subdomain effected by this .htaccess that do not have an .extention (EG .htm .html .php, etc) and do not end in a / will be rewritten to www.example.com/thecompletepath/

It looks like using extentionless files was the goal here, but am not sure - Could you please post exactly what these rules are designed to accomplish, then maybe we can help you come up with something that works for your subdomains and is more effecient for your main domain.

Justin

jdMorgan

1:16 am on Aug 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The following code does not check for subdomain requests, and so cannot rewrite/redirect them to subdirectories.

# If request to example.com domain
RewriteCond %{HTTP_HOST} ^example.com
# Redirect to same page in www.exxample.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#
# Commented-out in original file. These do nothing.
#RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
#RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
#
# If no dot followed by 2 to 4 characters (that is, if no filetype) in URL, then execute next rule
RewriteRule !\..{2,4}$ - [C]
# If no trailing slash
RewriteCond %{REQUEST_URI} !^/.+/$
# Redirect to same page with trailing slash added
RewriteRule ^(.+)$ http://www.example.com/$1/ [R=301,L]
#
# The following two lines don't do anything, because no rewriterule follows them
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d

This code is messy, but does not have anything to do with subdomains. I'd look elsewhere for other directives in other .htaccess files that may be affecting subdomain requests.

Jim

Added: No, jd01's right. It's the second ruleset doing it.

jdMorgan

1:22 am on Aug 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's a rewrite to fix it:

# If request to example.com domain
RewriteCond %{HTTP_HOST} ^example.com
# Redirect to same page in www.exxample\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#
# If no dot followed by 2 to 4 characters (that is, if no filetype) in URL, then execute next rule
RewriteCond %{REQUEST_URI} !\..{2,4}$
# and if not some path followed by trailing slash
RewriteCond %{REQUEST_URI} !^/.+/$
# Redirect to same page in same (sub)domain with trailing slash added
RewriteRule ^(.+)$ http://%{HTTP_HOST}/$1/ [R=301,L]

Jim

followgreg

11:16 am on Sep 10, 2005 (gmt 0)

10+ Year Member



God!

I forgot that I've posted the question here! THANK YOU so much!
Let me try it now :)

followgreg

8:30 pm on Sep 22, 2005 (gmt 0)

10+ Year Member



Unfortunately when I use this code it won't redirect the non-www to the www.example.com anymore for some reason :(