3

In my httpd.conf, I have

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule ^(.*)$ https://www.mysite.com/$1 [L,R=301]

But that's not working properly. I want the following to redirect to https://www.mysite.com:

How can I accomplish this?

2

Not sure what's not working properly. But the following will work:

RewriteCond %{SERVER_NAME} =mysite.com
RewriteRule  ^(.*)$        https://www.mysite.com/$1 [L,R=301]

RewriteCond %{HTTPS} off
RewriteRule (.*)           https://www.mysite.com/$1

This can be conceived as a duplicate post of many similar posts about rewrite rules on apache but I find this one particularly well worded about the redirect non-SSL so maybe this can be the last post that will need to be answered and people will be able to find that one easier!

  • do i need the =mysite.com or just mysite.com – Shamoon Apr 29 '13 at 20:47
  • I believe either way works. I have it with the equal sign but examples in Apache docs seems to show it without. – ETL Apr 29 '13 at 20:53
  • RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^mysite.com [NC] RewriteRule ^(.*)$ https://www.mysite.com/$1 [L,R=301] RewriteCond %{HTTPS} off RewriteRule (.*) https://www.mysite.com/$1 Doesn't seem to redirect to HTTPS – Shamoon Apr 29 '13 at 20:55
  • I fail to see how what you wrote in your comment here matches what I suggested. And what does not redirect? mysite.com or mysite.com or both? – ETL Apr 29 '13 at 20:59
  • both. I went a slightly different route for SSL – Shamoon Apr 29 '13 at 21:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.