简体   繁体   English

仅将htaccess主页https://a.com重定向到https://www.a.com重定向

[英]Htaccess only home page https://a.com to https://www.a.com redirect

My htaccess (codeigniter) 我的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>

if visitor open main page https://example.com need to redirect -> https://www.example.com 如果访问者打开主页https://example.com需要重定向-> https://www.example.com

But i have already redirect for my links. 但是我已经重定向了我的链接。 I need to do together current codes. 我需要一起做当前的代码。

How can i do? 我能怎么做?

Edit 1: 编辑1:

this is i want: 这是我想要的:

https://example.com -> https://www.example.com , https://example.com/somepage -> https://example.com/somepage (No change) , https://www.example.com/otherpage.html -> https://example.com/otherpage.html (No use www redirected) https://example.com - > https://www.example.comhttps://example.com/somepage - > https://example.com/somepage (无变化), https://开头WWW。 example.com/otherpage.html- > https://example.com/otherpage.html (不使用www重定向)

Only the main page will use www. 只有主页将使用www。 tag 标签

All other page not use www. 所有其他页面均不使用www。

Try this 尝试这个

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

You should use RedirectMatch to achive your goal. 您应该使用RedirectMatch实现目标。

Try this: 尝试这个:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用htaccess将http://www.example.com/重定向到https://www.example.com/ - redirect http://www.example.com/ to https://www.example.com/ with htaccess htaccess将域名a.com重定向到b.com/blog,并保留a.com地址 - htaccess redirect domain a.com to b.com/blog with keep a.com adress SSL错误:如何通过.htaccess将https://www.domain.com重定向到http://domain.com以避免SSL错误 - SSL Error: how to redirect https://www.domain.com to http://domain.com via .htaccess to avoid SSL error htaccess重定向到“ https:// www”。 - htaccess redirect to “https://www.” .htaccess www.mydomain.com/index.php?page=home到www.mydomain.com/home - .htaccess www.mydomain.com/index.php?page=home to www.mydomain.com/home Avoid multiple page redirects http://example.com &gt; https://example.com -&gt; https://www.example.com - Avoid multiple page redirects http://example.com > https://example.com -> https://www.example.com htaccess https://example.com/dash/something 链接重定向问题 - htaccess https://example.com/dash/something link redirect problem 使用htaccess将http:// www,http://和https:// www重定向到https: - Using htaccess to redirect http://www, http:// and https://www to https: http to https AND //domain.com to www.domain.com AND subdomain.domain.com to subdomain.domain.com through htaccess - http to https AND //domain.com to www.domain.com AND subdomain.domain.com to subdomain.domain.com through htaccess .htacces从example.com/abc重定向到https://www.example.com/abc - .htacces redirect from example.com/abc to https://www.example.com/abc
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM