我正在使用SSL证书运行网站。htaccess规范名称重定向
为了优化我的搜索引擎优化,我想将所有的CNames重定向到https://example.com。
有相同的地址的4种变体: HTTPS://示例.com HTTPS://www.example.com中 HTTP://示例.com HTTP://www.example.com中
这段代码几乎工作:
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [OR]
RewriteCond %{HTTPS} =on
RewriteRule ^.*$ https://example.com/$0 [R,L]
然而,其中一个网址,不要重定向。如果我只输入example.com(http://example.com),则URL不会重定向到https://example.com。
任何人都可以帮助我与上面的代码纠正这一点?
回应乔恩下面的答案。我将代码片段添加到现有的.htaccess文件中。由于我不熟悉.htaccess,我想知道该代码片段的代码是否会导致重定向循环?
这里包括下面的代码片段的.htaccess文件:
<IfModule mod_rewrite.c>
RewriteEngine On
# Installation directory
RewriteBase/
# Protect application and system files from being viewed
RewriteRule ^(application|modules|system|tests|sql) - [F,L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php?kohana_uri=$0 [L,QSA]
#redirect CNames to non www
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [OR]
RewriteCond %{HTTPS} off
RewriteRule ^.*$ https://example.com/$0 [R,L]
</IfModule>
的[URL规范不重定向]可能重复(http://stackoverflow.com/questions/12763432/canonical-url-not-重定向) –