Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

In my httpd.conf, I have

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

But that's not working properly. I want the following to redirect to

How can I accomplish this?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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

RewriteCond %{SERVER_NAME}
RewriteRule  ^(.*)$$1 [L,R=301]

RewriteCond %{HTTPS} off
RewriteRule (.*) $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!

share|improve this answer
do i need the or just –  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} ^ [NC] RewriteRule ^(.*)$$1 [L,R=301] RewriteCond %{HTTPS} off RewriteRule (.*)$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? or 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 posting your answer, you agree to the privacy policy and terms of service.

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