简体   繁体   中英

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

My 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

But i have already redirect for my links. I need to do together current codes.

How can i do?

Edit 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)

Only the main page will use www. tag

All other page not use www.

Try this

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

You should use RedirectMatch to achive your goal.

Try this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM