Apache Virtualhost redirect not working

I have two simple redirects set up in my virtual host for a subdomain; one works and the other doesn't:

<VirtualHost *:80>
 ServerName subdomain.site.com
 Redirect / https://subdomain.site.com/subdirectory/login.php
</VirtualHost>

<VirtualHost x.x.x.x:443>
 ServerName subdomain.site.com
 Redirect / https://subdomain.site.com/subdirectory/login.php
 SSLEngine on
 SSLCertificateFile /etc/httpd/ssl/subdomain.site.com.crt
 SSLCertificateKeyFile /etc/httpd/ssl/subdomain.site.com.key
 ErrorLog logs/ssl_error_log
 CustomLog logs/ssl_access_log common
</VirtualHost>

      

The first forwarding works. That is, if someone just types subdomain.site.com in their browser, it redirects to https and to the correct subdirectory. The second redirect doesn't work. If someone types in https://subdomain.site.com , they say, "Firefox has detected that the server is redirecting the request for this address in a way that will never complete" and the browser URL becomes "subdomain.site.com /subdirectory/login.phpsubdirectory/login.phpsubdirectory/login.phpsubdirectory/login.php ... "instead of redirecting to the correct https://subdomain.site.com/subdirectory/login.php . Can anyone point me in the right direction?

Edit: I updated the above VirtualHosts file to a newer version and the problem changed, so I updated the problem description as well.

+3


source to share


4 answers


Ok, none of the answers above worked, so I had to keep working on it. I ended up removing the redirect line from the virtual host: 443 section and adding the following two lines in the same section to get this to work correctly:



RewriteEngine On
RewriteRule ^/$ https://subdomain.site.com/subdirectory/login.php [R=301,NC,L]

      

+2


source


You must add this line to the beginning of the file

NameVirtualHost xxxx: 443 or domain name: 443



check your Apache version.

+1


source


You must add this line to the beginning of the file:

NameVirtualHost x.x.x.x

      

and

Listen 80
Listen 443

      

considers

0


source


if you are on ubuntu (I mean debian based linux distro) in your / etc / hosts you must define a line like below: 127.0.0.1 yourdomain

and then create a new file for the new site config: / etc / apache2 / sites-accessible /

and name it as your domain name .conf so you don't forget what this conf file is for. then enable the new conf with the following a2ensite your_conf_name command then restart apache. now your new site configuration is ready. now look at the following link: http://httpd.apache.org/docs/2.2/bind.html you should mention that your apache has to listen on multiple ports in your case 80, 443

0


source







All Articles