简体   繁体   中英

Apache Virtualhost Redirect Not Working

I have two simple redirects set up in my virtualhost for a subdomain; one is working, one is not:

<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 redirect is working. That is, if someone simply types in subdomain.site.com in their browser it redirects to https and to the correct subdirectory. The second redirect is not working. If someone types in https://subdomain.site.com it says "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 page. Can anyone point me in the right direction?

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

Alright, none of the answers above worked so I had to keep working on this. Ultimately I removed the redirect line from the :443 virtualhost section and added the following two lines to the same section to get this to work correctly:

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

You have to add this line to top of file

NameVirtualHost xxxx:443 or domaine name:443

check you apache version.

You have to add this line to top of file :

NameVirtualHost x.x.x.x

and

Listen 80
Listen 443

regards

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

and then in make a new file for your new site configuration in : /etc/apache2/sites-available/

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

If you are using SSL you should change default-ssl.conf settings like

<VirtualHost *:443>
    ServerName subdomain.site.com
    ServerAlias subdomain.site.com  
    DocumentRoot /var/www/html/subdomain.site.com

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM