The subdomains blog.mysite.com and talk.mysite.com work fine, but any new subdomains I create don’t. For example, I created a subdomain that should display @ books.mysite.com, but it redirects to https://www.books.mysite.com/
After doing a little research, I thought the following rule might fix it:
RewriteCond %{HTTP_HOST} !^books.mysite.co$ [NC]
…but I’m writing it incorrectly or inserting it in the wrong location. Or maybe I need a completely different rule.
My .htaccess file is a can of worms, because i’ve had to jump through many hoops to make things work. First, I created some rules to force my URL’s to default to lower case and replace underscores (and spaces) with hyphens.
When I converted my site from http to https I had to fix a new series of problems. I thought my webhost fixed one problem by barring my subdomains from https. However, I just checked, and I can view blog.mysite.com at either https or http.
Anyway, this is what my webhost told me:
"I’ve looked into this and found that it is due to the rewrites you’ve got setup in /home/username/public_html/.htaccess, specifically the ones on lines 31 to 38, which first redirect to https (line 29) and then redirect to www if not already www (line31) and ultimately to https and www (line 34).
“This is affecting the subdomains because an .htaccess file affects sub-directories as well as the directory it exists within, so if you want these subdomains to not get redirected like this then you’ll need to exclude them with a new rule in that file.”
I deleted five lines of extraneous code at the top, so I think the line numbers he gave extrapolate to “26-33,” “(line 24),” “(line 26)”, and “(line 29).”
Anyway, sorry for the can of worms, but can anyone give me a rule that will make a subdomain at /public_html/books display at books.mysite.com - and tell me where I should insert it?
Thanks!
# Add /? before first $ in every row if you want optional trailing slashes.
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^test\.htm$ test.php [L]
Options -MultiViews
##########
# NEW RULES...
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^([^_\ ]*)[_\ ](.*?[_\ ].*) $1-$2 [N]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^([^_\ ]*)[_\ ]([^_\ ]*) /$1-$2 [L,R=301]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*?[A-Z].*) /${tolower:$1} [R]
ErrorDocument 404 /404.php
##########
# Redirect traffic to https...
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
##########
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^cp/([a-zA-Z0-9()_/-]+)/?$ cp/index.php?cp=$1 [L]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^introduction/([a-zA-Z0-9()_/-]+)/?$ introduction/index.php?intro=$1 [L]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^search/([a-zA-Z0-9()_/-]+)/?$ search/index.php?search=$1 [L]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^welcome/([a-zA-Z0-9()_/-]+)/?$ welcome/index.php?welcome=$1 [L]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^about/([a-zA-Z0-9()_/-]+)/?$ about/index.php?about=$1 [L]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^dictionary/([a-zA-Z0-9()_/-]+)/?$ dictionary/index.php?dict=$1 [L]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^calendar/([a-zA-Z0-9()_/-]+)/?$ calendar/index.php?cal=$1 [L]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^world/([a-zA-Z0-9()_/-]+)/?$ world/index.php?area=$1 [L]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^contact/([a-zA-Z0-9()_/-]+)/?$ contact/index.php?contact=$1 [L]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^club/([a-zA-Z0-9()_/-]+)/?$ club/index.php?club=$1 [L]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^zadmin/([a-zA-Z0-9()_/-]+)/?$ zadmin/index.php?zadmin=$1 [L]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^test/([a-zA-Z0-9()_/-]+)/?$ test/index.php?test=$1 [L]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^/?([-a-zA-Z0-9_/]+)/?$ /index.php?encyc=$1 [L]