Redirect non-www to www for https

Hi All,

I am having one live site say https://www.mysite.com. I want, when any user types mysite.com it should get redirected to https://www.mysite.com.
I have added rewrite rule for this and it is working.

RewriteCond %{HTTP_HOST} ^www\.mysite.\.com$
RewriteRule ^/?$ "http\:\/\/mysite\.com\/" [R=301,L]

However, the issue is I have page
https://www.mysite.com/mypage/myprofile and other pages.

if user types https://mysite.com/mypage/myprofile, it should get redirected to https://www.mysite.com/mypage/myprofile. This is not happening currently.

Your help will be highly appreciated.

I’m no expert with htaccess but try this

RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule .? http://www.domain.com%{REQUEST_URI} [R=301,L]

This is the correct method.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com [nc]
RewriteRule (.*) https://www.yoursite.com/$1 [R=301,L]

This would help you out.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.