Thursday, January 7, 2016

Apache redirect from site-domain.com to www.site-domain.com

I want whenever we access site-domain.com it should be redirected to https://www.site-domain.com/users/sign_in.




Here is my config




ServerName www.site-domain.com
DocumentRoot /var/www/current/public

RailsEnv copsvpc

SSLEngine on
SSLOptions +StrictRequire

SSLCertificateFile /etc/apache2/ssl/certs/cert.crt
SSLCertificateKeyFile /etc/apache2/ssl/private/site-domainV2.key
SSLCertificateChainFile /etc/apache2/ssl/certs/inertermediateCA.crt


Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all




RewriteEngine on
RewriteCond %{HTTP:Cookie} !help=([a-zA-Z0-9]+)
RewriteRule ^(.*)$ /users/sign_in [L,R]






RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]



Should I simply add the following



ServerAlias site-domain.com
RewriteEngine On

RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]


I can not test this as site can not go down.



So it would be like




ServerName www.site-domain.com
DocumentRoot /var/www/current/public

ServerAlias site-domain.com

RailsEnv copsvpc

SSLEngine on
SSLOptions +StrictRequire
SSLCertificateFile /etc/apache2/ssl/certs/cert.crt
SSLCertificateKeyFile /etc/apache2/ssl/private/site-domainV2.key
SSLCertificateChainFile /etc/apache2/ssl/certs/inertermediateCA.crt


RewriteEngine On
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]



Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all




RewriteEngine on
RewriteCond %{HTTP:Cookie} !help=([a-zA-Z0-9]+)
RewriteRule ^(.*)$ /users/sign_in [L,R]






I can ping www.site-domain.com but not site-domain.com.
Do we need an entry for site-domain.com in DNS as well?
I would really appreciate any help.



Thanks in advance

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...