Forum Moderators: phranque
http to https - Final Checklist
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{REQUEST_URI} ^(/[^/]+/)/+(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^(/)/+(.*)$
RewriteRule ^. http://www.example.co.uk%1%2 [R=301,L]
RewriteCond %{HTTP_HOST} ^mail\.example\.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.example.co.uk/$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^(/[^/]+/)/+(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^(/)/+(.*)$
RewriteRule (.*) [%{HTTP_HOST}%{REQUEST_URI}<...]
Typo missing [R=301,L] flags? Target should be explicit
[example.co.uk...]
or
[example.co.uk...]
to intercept anyone who gave the wrong form of the hostname. And there's no point in capturing the request if you're just going to say %{REQUEST_URI} at the end. If you do capture, make sure to leave off unwanted directory names. That's assuming the rule is lying loose in config, not in a <Directory> section corresponding to the site root.
Target should be explicit
[example.co.uk...]
actually since that is in the httpd.conf file the slash is extraneous so the target should be:
[example.co.uk$1...]
RewriteCond %{HTTPS} off
i prefer checking %{SERVER_PORT} instead of %{HTTPS}.
Note that the conf file already contains other redirects such as:
RewriteCond %{REQUEST_URI} ^(/[^/]+/)/+(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^(/)/+(.*)$
RewriteRule ^. http://www.example.co.uk%1%2 [R=301,L]
RewriteCond %{HTTP_HOST} ^mail\.example\.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.example.co.uk/$1 [R=301,L]
So do I leave that as-is, then add the http to https redirect after it? Or do I need to duplicate this section with another section for https?
i assume the purpose of that first ruleset is to strip extraneous consecutive slashes at the end of the directory path?
shouldn't this also redirect to https: protocol?
are any canonical urls non-https:?
you don't need the second ruleset if you replace it with the following, which should typically be the final ruleset among the external redirects:# redirect secure pages to HTTPS:
# if requested with HTTP (i.e. server port is NOT 443)
# OR
# if requested with non-canonical hostname
# then 301 redirect to the canonical protocol and hostname
RewriteCond %{SERVER_PORT}!^443$ [OR]
RewriteCond %{HTTP_HOST} !^(www\.example\.co\.uk)?$ [NC]
RewriteRule ^(.*)$ https://www.example.co.uk$1 [R=301,L]
since that is in the httpd.conf file the slash is extraneous
/sites/username/example.co.uk/directory/subdir/filename ^(/)
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.example.co.uk
Redirect permanent / https://www.example.co.uk/
</VirtualHost>
Redirect permanent / https://www.example.co.uk/ If you are not supposed to mix them what are the consequences? No error is being displayed.
you only find out if both "" and "www." are covered after you make purchase
If you are not supposed to mix them what are the consequences?
when there are Redirect and RewriteRule directives in the same scope, the RewriteRule directives will run first, regardless of the order of appearance in the configuration file
Nobody will ever use the "wrong" form of your name except robots and the odd type-in, and you'd be redirecting those anyway.
nnn.nnn.nnn.nnn - - [12/Feb/2015:22:48:59 +0000] "GET /articles/old_article_name.html HTTP/1.1" 301 263 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko" 0 example.co.uk "-" "-"
nnn.nnn.nnn.nnn - - [12/Feb/2015:22:48:59 +0000] "GET /articles/old_article_name.html HTTP/1.1" 301 259 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko" 0 www.example.co.uk "-" "-"
nnn.nnn.nnn.nnn - - [12/Feb/2015:22:48:59 +0000] "GET /blog/old_article_name.html HTTP/1.1" 301 259 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko" 0 www.example.co.uk "-" "-"
nnn.nnn.nnn.nnn - - [12/Feb/2015:22:48:59 +0000] "GET /blog/nicer-article-name.html HTTP/1.1" 200 7711 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko" 0 www.example.co.uk "-" "-"
#1 redirect any specific names that will be changing
RewriteRule (blog|articles)/old_article_name.html https://www.example.co.uk/blog/nicer-article-name.html [R=301,L]
#2 redirect anything else that used to be in articles and will now be in blog
# with preceding RewriteCond if only selected names are moving
RewriteRule articles/(capture-stuff-here) https://www.example.co.uk/blog/$1 [R=301,L]
#3 mop-up redirect only for requests that have not been handled earlier
RewriteCond %{SERVER_PORT}!^443$ [OR]
RewriteCond %{HTTP_HOST} !^(www\.example\.co\.uk)?$ [NC]
RewriteRule /first-part-of-path/(.*)$ https://www.example.co.uk/$1 [R=301,L]
g) Do I need to do anything in WMT? Google Analytics? Adsense?