在Rails应用程序中redirect用户之后,由于某种原因,缺less域之后的斜杠。 生成的url无效,我不得不手动更正它们。 该问题只发生在一个子域上。 在不同的主域(相同的服务器)上,一切正常。
例如,注销后,该网站正在转到https://www.sub.domain.comlogin/,而不是https://www.sub.domain.com/login
我怀疑这个问题与虚拟主机设置有关,但我不确定。 这里是破碎和工作的鬼魂:
损坏的子域
<VirtualHost *:80> ServerName www.sub.domain.com ServerAlias sub.domain.com Redirect permanent / https://www.sub.domain.com </VirtualHost> <VirtualHost *:443> ServerAdmin [email protected] ServerName www.sub.domain.com ServerAlias sub.domain.com RailsEnv production # SSL Engine Switch SSLEngine on # SSL Cipher Suite: SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL # Server Certificate SSLCertificateFile /path/to/server.crt # Server Private Key SSLCertificateKeyFile /path/to/server.key # Set header to indentify https requests for Mongrel RequestHeader set X_FORWARDED_PROTO "https" BrowserMatch ".*MSIE.*" \ nokeepalive ssl-unclean-shutdown \ downgrade-1.0 force-response-1.0 DocumentRoot /home/usr/www/www.sub.domain.com/current/public/ <Directory "/home/usr/www/www.sub.domain.com/current/public"> AllowOverride all Allow from all Options -MultiViews </Directory>
工作的主要领域
<VirtualHost *:80> ServerName www.diffdomain.com ServerAlias diffdomain.com Redirect permanent / https://www.diffdomain.com </VirtualHost> <VirtualHost *:443> ServerAdmin [email protected] ServerName www.diffdomain.com ServerAlias diffdomain.com ServerAlias *.diffdomain.com RailsEnv production # SSL Engine Switch SSLEngine on # SSL Cipher Suite: SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL # Server Certificate SSLCertificateFile /path/to/server.crt # Server Private Key SSLCertificateKeyFile /path/to/server.key # Set header to indentify https requests for Mongrel RequestHeader set X_FORWARDED_PROTO "https" BrowserMatch ".*MSIE.*" \ nokeepalive ssl-unclean-shutdown \ downgrade-1.0 force-response-1.0 DocumentRoot /home/usr/www/www.diffdomain.com/current/public/ <Directory "/home/usr/www/www.diffdomain.com/current/public"> AllowOverride all Allow from all Options -MultiViews </Directory> </VirtualHost>
请让我知道,如果有什么我可以提供,这将有助于确定这里有什么问题。
更新尝试添加一个尾随斜杠redirect命令,但仍然没有运气。
我相当肯定你需要在redirect命令上的斜杠:
Redirect permanent / https://www.sub.domain.com/
问另一个开发者关于这个,以下是他如何解决这个问题:
我为你做了一个新的虚拟主机文件。 在之前的vhostconfiguration中,服务器名称和服务器别名上出现错误。 我删除了“www”。 另外我添加了config.force_ssl = true到environments / production.rb
<VirtualHost *:80> ServerName sub.domain.com ServerAlias sub.domain.com www.sub.domain.com Redirect permanent / https://sub.domain.com </VirtualHost> <VirtualHost *:443> ServerAdmin [email protected] ServerName sub.domain.com ServerAlias sub.domain.com RailsEnv production RailsBaseURI / # SSL Engine Switch SSLEngine on # SSL Cipher Suite: SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL # Server Certificate SSLCertificateFile /path/to/server.crt # Server Private Key SSLCertificateKeyFile /path/to/server.key # Set header to indentify https requests for Mongrel RequestHeader set X_FORWARDED_PROTO "https" BrowserMatch ".*MSIE.*" \ nokeepalive ssl-unclean-shutdown \ downgrade-1.0 force-response-1.0 DocumentRoot /home/usr/www/www.sub.domain.com/current/public/ <Directory "/home/usr/www/www.sub.domain.com/current/public"> AllowOverride all Allow from all Options -MultiViews </Directory> </VirtualHost>