Reputation: 299
I have a problem where all the links in my site are broken when the site is in https. Anyway what I need to do is redirect all request from http
to https
so I added the code below in .htaccess
.
# Redirect from http to https.
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^project-local\.com*
RewriteRule ^(.*)$ https://project-local.com/$1 [L,R=301]
Redirection is working fine but what happen if I click any link in the site while it is in https all response is 404.
This is my ssl vhost looks like:
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerName project-local.com
DocumentRoot /home/snake/repo/project-a/docroot
ErrorLog ${APACHE_LOG_DIR}/project-a-ssl_error.log
CustomLog ${APACHE_LOG_DIR}/project-a-ssl_access.log common
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
<Directory /home/snake/repo/project-a/docroot/>
Require all granted
</Directory>
BrowserMatch "MSIE [2-6]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
# MSIE 7 and newer should be able to use keepalive
BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
</VirtualHost>
</IfModule>
Upvotes: 2
Views: 216
Reputation: 784948
Your http->https
rule isn't correct and it can cause infinite redirections, you can use:
RewriteCond %{HTTP_HOST} ^project-local\.com$ [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301,NE]
Upvotes: 1