Forum Moderators: phranque
[size=2]Options +FollowSymLinks
RewriteEngine On
# redirect index.htm and index.html to /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html?\ HTTP/
RewriteRule ^(.*)index\.html?$ http://www.mydomain.com/$1 [R=301,L]
# redirect no-www to www.
RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L][/size]
I have 4 other addon domains. Not subdomains. With this code in place when I go to the addon domain it forces it to read in the url http: //www (dot)topleveldomain(dot)com/addondomain(dot)com
Can you show me what that would look like please?
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.(html?|php)\ HTTP/
RewriteRule ^(([^/]+/)*)index\.(html?|php)$ http://www.example.com/$1 [R=301,L] RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L] RewriteCond %{HTTP_HOST} !(example\.net|example\.org|example\.co\.uk)
[edited by: lucy24 at 6:44 pm (utc) on Oct 16, 2012]
If I don't have a index file in one of the addon domains it redirects to the main domain. Is this normal behavior for the below htacces code?
Like it to NOT redirect to main/addon if there is no index file on the addon that is.
# 301 permanent redirect index.php to folder
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://www.exampledomain.com/$1 [R=301,L]
# 301 permanent redirect non-www (non-canonical) to www
RewriteCond %{HTTP_HOST} !^(www\.exampledomain\.com)?$
RewriteRule (.*) http://www.exampledomain.com/$1 [R=301,L] RewriteEngine on
# Send subdomains off to their own domains so
# you don't need to worry about exclusions below
RewriteCond %{HTTP_HOST} ^((www\.)?([a-z]+\.))maindomain\.com$ [NC]
# Capture optional www and subdomain (better to list your subdomains inside (sub1|sub2|...) )
RewriteRule .? http://%1com{%REQUEST_URI} [R=301,L]
# Send {REQUEST_URI} to subdomain.com
# Note, this can also send to www.maindomain.com
# (if you don't list as recommended above) but
# that will be corrected below
# 301 permanent redirect index.html(htm) to folder with exclusion for addon domains
# Rephrased: Strip subdirectories from any index.htm(l) request
# RewriteCond %{HTTP_HOST} !(addondomain\.com|addondomain\.com|addondomain\.com|addondomain\.com|addondomain\.com)
# Irrelevant
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html?\ HTTP/
# {THE_REQUEST} is a terrible variable to use and you don't need to use the whole thing!
# In fact, you don't need to use it at all!
RewriteRule .+/index\.html?$ http://www.maindomain.com/index.html [R=301,L]
# 301 permanent redirect non-www (non-canonical) to www with exclusion for addon domains
RewriteCond %{HTTP_HOST} !(addondomain\.com|addondomain\.com|addondomain\.com|addondomain\.com|websitecodetutorials\.com)
# Ditto the above
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule .? http://www.maindomain.com${REQUEST_URI} [R=301,L]
The only reason I noticed it was because I just started developing it and took it live with no files. I was mainly just asking if this is normal behavior? I guess it is right? It redirects to folder if no index.
# Redirect index.html and .htm to folder
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html?\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html?$ http://www.example.com/$1 [R=301,L]
# Redirect non-canonical to www
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
If you have part of a site using https, then you'll need another rule for that, redirecting to https.
Correct. That code redirects everything to http and www.
If you have part of a site using https, then you'll need another rule for that, redirecting to https.
To make it all work, both of the rules will need extra preceding conditions: one testing the requested port is ^443$ or !^443$ and the other testing the requested path and file that should be http or should be https.
Conditions apply only to the next rule that follows.
You need the port test in some form or other ("is 443" or "is not 443") before every rule.
Add a blank line after each rule to make the code more readable.