Forum Moderators: phranque
Here is what I put in the .htaccess located in the domain account root directory (ie, public_html) to force no www, to force a trailing slash on the two directories that require it (but includes all directories), and to force https on the two directories:
------------------------
RewriteEngine On
RewriteBase /
#No .www in domain name
RewriteCond %{HTTP_HOST}!^domain.net$ [NC]
RewriteRule ^(.*)$ [domain.net...] [L,R=301]
#Force trailing / on all directories
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_URI}!(.*)/$
RewriteRule ^(.*)$ [domain.net...] [L,R=301]
#Force https on 'directory1' and 'directory2' directories
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} directory1 [OR]
RewriteCond %{REQUEST_URI} directory2
RewriteRule ^(.*)$ [domain.net...] [R,L]
------------------------
The circumstances that caused me to do this is people getting 403 on www.domain.net/directory1, domain.net/directory1, www.domain.net/directory2, and domain.net/directory2 with a forced https rewrite in directory1 and 2. The forced https in directories 1 & 2 worked only if they included a trailing / after the directory or went as far as to include index.html on the URL (except directory1 is all PHP). Not all people can figure that out and this is a money making site. I researched it and the above is what I came up with that works to overcome human error. The only problem that resulted is that now any [subdomain.domain.net...] comes up domain.net/subdomain in a browser. I can't find any rewrite rule that will fix the subdomain issue while keeping the above intact. Can someone help?
The only problem that resulted is that now any [subdomain.domain.net...] comes up domain.net/subdomain in a browserThat might be caused by yourn first rule, because your cond. is also true for a subdomain.
RewriteEngine On
#No .www in domain name
# the other way, host is www.domain.net
RewriteCond %{HTTP_HOST} =www.domain.net
RewriteRule ^(.*)$ http://domain.net/$1 [L,R=301]
#Force trailing / on all directories
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R=301]
#Force https on 'directory1' and 'directory2' directories
RewriteCond %{SERVER_PORT} =80
RewriteRule ^((directory1¦dir2).*)$ https://domain.net/$1 [R,L] [edited by: Caterham at 12:21 pm (utc) on Aug. 30, 2006]
RewriteEngine On
#No .www in domain name
# the other way, host is www.domain.net
RewriteCond %{HTTP_HOST} =www.domain.net
RewriteRule ^(.*)$ [domain.net...] [L,R=301]
However, this does work and it returned my subdomains back to subdomain.domain.com. (I got this one from [no-org...]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ [domain.com...] [R=301,L]
Thanks anyway for the assist!
RewriteCond %{HTTP_HOST} ^www\.domain\.c[b]om[/b] [NC]
RewriteRule (.*) http://domain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.domain\.com[b](:80)?[/b]$ [NC]
RewriteRule (.*) http://domain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.domain\.com[b](:[0-9]{1,5})?[/b]$ [NC]
RewriteRule (.*) http://domain.com/$1 [R=301,L]
Jim