I would like to force https connection through .htaccess in apache for vue.js history:
Vue history requires .htaccess like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
How can I modify this .htaccess to force SSL connection?
Line 3 and 4 are for redirecting to https.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
It is an old question but this what I'm using to force ssl in vue
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
Related
I want to forward request like this
http://www.website.com/ > https://www.website.com/ > https://website.com/
My .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Try :
RewriteCond %{HTTP_HOST} !^website\.com$
RewriteRule ^ https://domain\.com [R=301,L]
Based on your shown samples, try. Please make sure you clear your browser cache before testing your URLs. Make sure you are placing your https rule at the top of your htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine ON
RewriteBase /
RewriteCond %{HTTP_HOST} ^(?:www\.)(.*)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [NE,R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I have got my .htaccess file working for my main domain (www.domain.com):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
However, for my Subdomain www.domain.com/subdomain/ the icon starts as a secure padlock but then goes to unsecure. I am using this in the .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Any ideas on what I should put in the subdomain file?
Figured this out, there was an image using an external URL.
Https redirection is working fine for main website but having problem with the blog. Any of these doesn't work for me.
Test1
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{HTTPS} off
RewriteRule ^(.*) https://example.com/blog/$1 [R,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)$ /blog/index.php [L]
</IfModule>
Test2
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{HTTPS} off
RewriteRule ^blog/(.*) https://example.com/blog/$1 [R,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)$ /blog/index.php [L]
</IfModule>
My .htaccess file is shown below
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Recently I have installed the SSL, so I needs to make sure that my customers connect to my website in HTTPS. So what changes I needs to make in this code to load my website in SSL
To load your site in SSL ,you can use
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#http to https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R]
###########
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I have the following HTTP address:
http://www.example.com/
but my HTTPS address has a subdomain and no www, like this:
https://secure.example.com/
I tried the following rule:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://secure.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
Which sent me to:
https://secure.www.example.com/
How can I force HTTPS in this situation? As I need the www removed.
EDIT: I have these rules above them for 'fancy urls' as I'm using WordPress as CMS:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
This should be your complete htaccess :
RewriteEngine On
RewriteBase /
#1--Redirect "http://domain to "https://secure"
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://secure.domain.com%{REQUEST_URI} [L,R=301]
#2--wp rules--#
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://secure.example.com/$1 [L,R=301]
</IfModule>
OR
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://secure.example.com/$1 [R=301,L]
Both rules do exactly this: any non-https request is redirected to https://secure.example.com while preserving the whole url