Reload if no www. is present via HTACCESS
Currently we do it per site in the .htaccess, is there away to regex this piece of code up?
RewriteCond %{HTTP_HOST} ^soupandcookies.com
RewriteRule (.*) http://www.soupandcookies.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^soupandcookies-takeaway.com
RewriteRule (.*) http://www.soupandcookies-takeaway.co开发者_运维问答m/$1 [R=301,L]
As it has been a chore as we are starting to us ALOT of domains on one codebase.
Many thanks
For non-HTTPS requests:
RewriteCond %{HTTPS} =off
RewriteCond %{SERVER_NAME} !^www\.
RewriteCond %{SERVER_NAME} ^(.+)$
RewriteRule (.*) http://www.%1/$1 [R=301,L]
And for HTTPS requests:
RewriteCond %{HTTPS} =on
RewriteCond %{SERVER_NAME} !^www\.
RewriteCond %{SERVER_NAME} ^(.+)$
RewriteRule (.*) https://www.%1/$1 [R=301,L]
Also note that relying on HTTP_HOST
is unsecure. Its value is taken from the HTTP header field Host: ...
which can be forged, if your default vhost handles all requests.
精彩评论