0

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

https://test

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

10.10.86.1 - - [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

10.10.86.1 - - [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'

10.10.86.1 - - [05/Apr/2012:15:10:19 --0700] [test/sid#7ce00][rid#277448/initial/redir#1] (4) RewriteCond: input='off' pattern='!=on' => matched

10.10.86.1 - - [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]

10.10.86.1 - - [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]

10.10.86.1 - - [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

10.10.86.1 - - [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]

10
  • why not rewrite out of curiosity? Apr 4, 2012 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, 2012 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. Apr 4, 2012 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, 2012 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 Apr 4, 2012 at 21:56

2 Answers 2

1

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

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

0

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.

i.e.

Listen 12.34.56.78:80
<virtualhost 12.34.56.78:80>
Blah
some more config stuff
DocumentRoot /var/www/null
redirect permanent / https://test/
</virtualhost>

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.

1
  • 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 10.10.10.10:80 <VirtualHost 10.10.10.10:80> DocumentRoot /var/apache2/htdocs Redirect permanent / https://test/ </VirtualHost>
    – eli1128
    Apr 4, 2012 at 16:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .