开发者

Reload if no www. is present via HTACCESS

开发者 https://www.devze.com 2023-02-02 20:29 出处:网络
Currently we do it per site in the .htaccess, is there away to regex this piece of code up? RewriteCond %{HTTP_HOST} ^soupandcookies.com

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消