I'm having issues forcing an SSL on my website. I think the issue may be that my root folder is my 'web' folder.
I've searched online and tried a few variations of htaccess but none of them seem to work.
Here is the latest I've tried:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Send would-be 404 requests to Craft
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
RewriteRule (.+) index.php?p=$1 [QSA,L]
</IfModule>
My domain points to my web folder and my htaccess belongs in the web folder.
Thanks,
Joe
When you accept traffic on port 80 and port 443 and use Apache, you usually have 2 virtual host configurations: one for each port. A simple approach would therefore be to simply redirect any incoming port 80 requests to the SSL/TLS-enabled URL:
<VirtualHost *:80>
ServerName example.com
RedirectMatch permanent (.*) https://example.com$1
</VirtualHost>
If you want to handle several hostnames, mod_rewrite might come in handy (to my knowledge, RedirectMatch does not support variables such as %{HTTP_HOST}), but if not, that’s it.
Related
I had some issues with my apache configuration and I'm trying to isolate the problem.
I came up with the following lines which are not working :
For testing purposes, I'm trying to redirect all https traffic to Yahoo
The redirection is not working and my web site is showing the index.html file stored in public_html
Listen 443
NameVirtualHost *:443
<VirtualHost *:443>
DocumentRoot "${SRVROOT}/htdocs/example.com/public_html"
ServerName example.com
ServerAlias example
Redirect permanent / https://www.yahoo.com/
</VirtualHost>
Can anyone help please ?
Thanks
Use this for the redirect, also enable mod_rewrite for this to work:
Add this to the top of your .htaccess file:
RewriteEngine On #Don't use RewriteEngine On twice in one .htaccess file
RewriteBase /
RewriteRule ^(.*)$ https://www.yahoo.com [R=301,L]
Clear your browser's cache to have a different redirect than yahoo.com, once it works.
Just in case
If you want all traffic of your website to redirect to https:// on the same domain, do the following, don't remove RewriteEngine On and RewriteBase /:
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
If you want to redirect all traffic to one domain with https:
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST] !^example.com
RewriteRule ^(.*)$ https://example.com [R=301,L]
If you want to redirect all traffic to one domain with https and www:
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST] !^www.example.com
RewriteRule ^(.*)$ https://www.example.com [R=301,L]
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}
I am trying to redirect my site and I seem to run into an issue each time I try to get it to redirect to https://example.com from www.example.com.
If I type example.com in the browser it redirects me fine to https://example.com. I get the following message whenever I type www.example.com instead of just example.com.
This site can’t provide a secure connection
www.example.com uses an unsupported protocol.
ERR_SSL_VERSION_OR_CIPHER_MISMATCH
HIDE DETAILS
Unsupported protocol
The client and server don't support a common SSL protocol version or cipher suite.
I have tried many different rewrite conditions in my htaccess file but none seem to work.
This is what I currently have as of my last test...
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect all connection to SSL/443
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^(.*)$ "https\:\/\/example\.com\/$1" [R=301,L]
If anyone could help in getting the redirect from the www version to the non-www version using https it would be highly appreciated.
Thank you very much in advance.
Do you have a valid SSL certificate and can you go to https://example.com without an error?
Otherwise change the last line to:
RewriteRule ^(.*)$ "http://example.com/$1" [R=301,L]
Having a difficult time finding the combination to satisfy the following 3 conditions. What Rewrite rules and conditions will accomplish the conditions? (I've already been surprised by the rules not working.)
www stripped from all requests
https for all requests to primary
http for all requests to subdomain (in subfolder of main site) subdomain.com
htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.primary\.mobi [NC,OR]
RewriteCond %{HTTP_HOST} ^primary\.mobi [NC,OR]
RewriteCond %{HTTP_HOST} !^(www\.)?subdomain\.com [NC]
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
The above do not strip www and send www.subdomain to https.
Explanations welcomed. Trying to understand the apache mod_rewrite manual page and have tried several methods without success.
You can capture the domain and use it in your RewriteRule. HTTP_REQUEST is not available in the substitution part, but only in RewriteCond directives.
I'm not sure, but you can try to split this into two .htaccess files. This one goes into the main directory
RewriteEngine On
# remove www. from HTTPS requests
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(primary\.mobi)$ [NC]
RewriteRule .* https://%1/$0 [R,L]
# redirect HTTP requests to HTTPS
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(primary\.mobi)$ [NC]
RewriteRule .* https://%1/$0 [R,L]
and this is for the .htaccess in the subdomain folder
RewriteEngine On
# remove www. from HTTP requests
RewriteCond %{HTTP_HOST} ^www\.(subdomain\.com)$ [NC]
RewriteRule .* http://%1/$0 [R,L]
# redirect HTTPS requests to HTTP
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(subdomain\.com)$ [NC]
RewriteRule .* http://%1/$0 [R,L]
Test your rules without 301, because the browser caches 301 results and makes testing much harder. Add R=301 not until you're satisfied with the rules.
In Canonical Hostnames are some alternatives described, especially the first one, using virtual hosts, looks promising
<VirtualHost *:80>
ServerName www.primary.mobi
Redirect / https://primary.mobi/
</VirtualHost>
<VirtualHost *:80>
ServerName primary.mobi
</VirtualHost>
<VirtualHost *:80>
ServerName www.subdomain.com
Redirect / http://subdomain.com/
</VirtualHost>
<VirtualHost *:80>
ServerName subdomain.com
</VirtualHost>
I don't know, if this is feasible for you, but you might try.
I know, this should be easy, but I cannot make it work.
I have 2 domains pointing to the same folder in an Apache server, bahiadivers.com and bahiadivers.cl.
I want to redirect bahiadivers.cl to bahiadivers.cl/es/ and change the address bar.
I try this (among a million things)
rewritecond %{HTTP_HOST} ^bahiadivers.cl [nc]
rewriterule ^/$ http://www.bahiadivers.cl/es/$1 [r=301,nc]
but didn't work... I mean, the URL is not changing in the browser address bar, but also the languge (/es/) is not working... how should I do this?
Thanks!
Try this for your .htaccess
# Apache configuration file
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine on
# If URL is www.example.com/es/Blah, use /Blah/
# Prevents needing to change existing links.
RewriteBase /es/
# Rewrite www.example.com to example.com
RewriteCond %{HTTP_HOST} ^www.bahiadivers.cl
RewriteCond %{HTTP_HOST} ^bahiadivers.cl
# Rewrite any inbound URL Bits to http://bahiadivers.cl/es/...
RewriteRule (.*) http://bahiadivers.cl/es/$1 [R=301,L]
</IfModule>
That should do it.
I'm sorry for yet another of these posts, but from what I can tell, my question is different than the prevailing http -> https redirects out there.
I want to
redirect all http://www.mydomain.com traffic to https://www.mydomain.com/wiki
AND
redirect https://www.mydomain.com to https://www.mydomain.com/wiki
Notice the https in my first redirect goal.
For the first redirect, I am able to accomplish this by putting:
RewriteEngine On
RewriteCond %{REQUEST_URI} /
RewriteRule ^(.*) https://%{SERVER_NAME}/wiki [R,L]
In my httpd.conf file and restarting.
I thought this would also work for my https:// attempts. Notice, I am not including
RewriteCond %{HTTPS} !=on
or anything like that. Yet, still https://www.mydomain.com sends me to my index.html file in my server root.
If I try to put the above Rewrite directives in my httpd-ssl.conf file and restart the server then I get infinite redirects.
What am I doing wrong?
NOTE: For what its worth, /wiki is an alias to /home/Users/myusername/www/wiki (the absolute path to wiki)
UPDATE
Rehash as to what I've tried so far:
Attempt 1:
In httpd.conf:
RewriteEngine On
RewriteCond %{REQUEST_URI} /
RewriteRule ^(.*) https://%{SERVER_NAME}/wiki [R,L]
In httpd-ssl.conf:
Nothing Rewrite related
Result 1:
Redirects all http traffic to https://www.mydomain.com/wiki
Does nothing for https://www.mydomain.com
Attempt 2:
In httpd.conf:
RewriteEngine On
RewriteCond %{REQUEST_URI} /
RewriteRule ^(.*) https://%{SERVER_NAME}/wiki [R,L]
In httpd-ssl.conf:
RewriteEngine On
RewriteCond %{REQUEST_URI} /
RewriteRule ^(.*) https://%{SERVER_NAME}/wiki [R,L]
Result 2:
Infinite redirects.
Attempt 3:
In httpd.conf:
RewriteEngine On
RewriteCond %{REQUEST_URI} /
RewriteRule !^wiki https://%{SERVER_NAME}/wiki [R,L]
In httpd-ssl.conf:
RewriteEngine On
RewriteCond %{REQUEST_URI} /
RewriteRule !^wiki https://%{SERVER_NAME}/wiki [R,L]
Result 3:
Infinite redirects.
Your rule will match every request (even /wiki). Try to exclude that:
RewriteRule !^wiki https://%{HTTP_HOST}/wiki [R,L]
The infinite redirects are coming from the fact that the rule matches both the first client request (eg. http://...) and from any subsequent request.
You would do better to use a rewrite rule which excludes the wiki path from the match e.g.
RewriteRule !^wiki https://%{HTTP_HOST}/wiki [R,L]
or you might get better performance from a RewriteCond
RewriteCond %{REQUEST_URI} !^wiki
before your existing rule. This will make it easier to add more complex patterns that you currently have in your example (should you need to later in your project).
I found a solution that might not be the most robust but it works for me.
In my httpd-ssl.conf file, under the VirtualHost container, I set the DocumentRoot to point to the directory that I've been trying to redirect to.
<VirtualHost _default_:443>
DocumentRoot "path on my HD where I wanted to redirect all along"
ServerName All the usual stuff...
...
This takes care of "redirects" (not really redirects anymore) for https transactions
For http (non-ssl) I placed in httpd.conf:
RewriteEngine On
RewriteCond %{REQUEST_URI} /
RewriteRule ^(.*) https://%{SERVER_NAME}/wiki [R,L]
That seemed to do it.