Htaccess只有主页https://a.com到https://www.a.com重定向

时间:2017-11-01 09:45:10

标签: php apache .htaccess codeigniter redirect

我的htaccess(codeigniter)

<IfModule mod_rewrite.c>

RewriteEngine On       

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^example\.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,NC,L]

RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteRule ^(.*)$ /index.php/$1 [L]

</IfModule>

如果访问者打开主页https://example.com需要重定向 - &gt; https://www.example.com

但我已经重定向了我的链接。我需要一起做当前的代码。

我该怎么办?

编辑1:

  

这是我想要的:

     

https://example.com - &gt; https://www.example.com,   https://example.com/somepage - &gt; https://example.com/somepage(不   变更),https://www.example.com/otherpage.html - &gt; https://example.com/otherpage.html(不使用www重定向)

     

只有主页面会使用www。标签

     

所有其他页面均不使用www。

2 个答案:

答案 0 :(得分:0)

试试这个

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

答案 1 :(得分:0)

您应该使用RedirectMatch来实现目标。

试试这个:

RedirectMatch 301 https://example.com https://www.example.com