Forum Moderators: phranque
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?
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
# 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
Jim
Added: No, jd01's right. It's the second ruleset doing 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]