Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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.