I want redirect my web site http request to https my web site is


my apache is version 2.4 and ssl configration is (ssl.conf) on separate file from httpd.conf and I am not using .htaccess file so where I should append. i have tried on both file but didn't work.

Redirect permanent / https://test

is that should be on my httpd.conf or ssl.conf or did I miss something else. I prefer to use redirect over rewrite.

Rewrite.log - - [05/Apr/2012:15:10:19 --0700] [test/sid#7ce00][rid#277448/initial/redir#1] (2) init rewrite engine with requested uri /error/HTTP_BAD_REQUEST.html.var - - [05/Apr/2012:15:10:19 --0700] [test/sid#7ce00][rid#277448/initial/redir#1] (3) applying pattern '^(.*)$' to uri '/error/HTTP_BAD_REQUEST.html.var' - - [05/Apr/2012:15:10:19 --0700] [test/sid#7ce00][rid#277448/initial/redir#1] (4) RewriteCond: input='off' pattern='!=on' => matched - - [05/Apr/2012:15:10:19 --0700] [test/sid#7ce00][rid#277448/initial/redir#1] (2) rewrite /error/HTTP_BAD_REQUEST.html.var -> *ttps://test/error/HTTP_BAD_REQUEST.html.var[QSA,R=301,L] - - [05/Apr/2012:15:10:19 --0700] [test/sid#7ce00][rid#277448/initial /redir#1] (2) implicitly forcing redirect (rc=302) with *ttps://test/error/HTTP_BAD_REQUEST.html.var[QSA,R=301,L] - - [05/Apr/2012:15:10:19 --0700] [test/sid#7ce00][rid#277448/initial/redir#1] (1) escaping *ttps://test/error/HTTP_BAD_REQUEST.html.var[QSA,R=301,L] for redirect - - [05/Apr/2012:15:10:19 --0700] [test/sid#7ce00][rid#277448/initial/redir#1] (1) redirect to *ttps://test/error/HTTP_BAD_REQUEST.html.var%5bQSA,R=301,L%5d [REDIRECT/302]

  • why not rewrite out of curiosity? – InChargeOfIT Apr 4 '12 at 16:46
  • apache web site recommend redirect over rewrite that's all, I am new to apache so I just follow what's written :) I am trying to learn. – eli1128 Apr 4 '12 at 16:51
  • rewrites are much more powerful.. however they are also more complex (but well worth the effort if you are a sysadmin). Without mod_rewrite, your Redirect statement should go in your httpd.conf file (in your virtual host block if you have one). Put it above your DocumentRoot directive if that makes it easier. You will need to restart apache for the changes to take affect. – InChargeOfIT Apr 4 '12 at 17:10
  • thanks much, I have added rewrite working like a charm. quick question, is that possible to redirect directly to https://test instead of now I am getting a message "Found" and the link for https://test – eli1128 Apr 4 '12 at 17:37
  • For rewrite try: RewriteCond %{HTTPS} !on and on the next line something like RewriteRule ^(.*)$ https://www.yourdomain.com%{REQUEST_URI} [QSA,R=301,L] QSA means 'append query string', the R=301 means Redirect (Moved permanently) and the L means Last.. as in stop processing rules here. Those two lines should redirect any traffic to https – InChargeOfIT Apr 4 '12 at 21:56

Since you're serving both HTTP and HTTPS, you're using virtual hosts.

That directive should go in the <VirtualHost> block for port 80.


You need two virtualhost configurations for this to work one listening on 80, the other listening on 443 for the SSL. You should put this inside your virtualhost tags inside the NON-SSL site. Then configure your SSL virtualhost (in ssl.conf) as normal.


some more config stuff
DocumentRoot /var/www/null
redirect permanent / https://test/

Just be careful about the trailing slash on the target site, if you don't have it in if someone puts in http://test/index.php your config will send them to https://testindex.php which won't exist.

  • I am new for apache so where exactly I have to add? because when I append Virtual host on httpd.conf apache won't start and complain ssl unable to load. so I guess I have added on wrong line on httpd.conf Listen <VirtualHost> DocumentRoot /var/apache2/htdocs Redirect permanent / https://test/ </VirtualHost> – eli1128 Apr 4 '12 at 16:15

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.