Here is a link to an almost identical question htaccess for redirecting non-www to www while preserving http & https

How would this be written for the opposite - I want to redirect www to non-www while preserving http or https, whatever the link may be originally

有帮助吗?

解决方案 2

This was what worked, after some trial and error:

# Make all http use https and force non-www
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ https://mysite.ca%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>

Sorry for not coming back to post this sooner, I'm learning...

其他提示

You can have these 2 rules:

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.+)$
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.+)$
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top