Why does my site load slowly after enabling SSL in .htaccess? - codeigniter

I have a site developed in CodeIgniter and after enabling SSL redirection, it started to load very slowly. I am using this for my redirection:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://visualimpacteastwest.com/$1 [R=301,L]
Any help would be appreciated .

The following code worked for me. Give a try:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
In your codeigniter application config file get the base url to blank:
*/application/config/config.php:
$config['base_url'] = "";

Related

Force https on Windows server

I have a windows server online and some pages load in http I would like to force them to https how could I do that ?
I have no idea where to start
You will need to change the code to the following in the .htaccess file.
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
You can reffer the following blog for reference if this doesn't work.
https://www.catalyst2.com/knowledgebase/server-management/how-to-force-https-on-linux-and-windows-servers/

My Laravel Routes is not working on CentOS

I just made a simple laravel application in CentOS running in apache server. The thing is I always gets an error:
"Not Found" when redirecting to other pages.
How do I fix this ? I'am completely new on using CentOS and apache server.
Note: It is working fine with Windows and xampp.
Here is my .htaccess file
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Try that route with index.php? like yourdomain.com/index.php/route-url and check if it works. If your homepage works and other pages do not, then your rewrite rule is no set.
Do
sudo a2enmod rewrite on
your server terminal and then restart apache
In Apache virtual host section add
AllowOverride all
And in your laravel's .htaccess add this :
Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
It's likely that you don't have Apache set up to properly rewrite your route and hand it to the index.php file. Have a look at the Apache section near the bottom of this page and ensure that your redirects mirror what this page lays out.

Laravel force HTTPS with .htaccess too many redirects using Amazon ELB

Pulling my hair out. I need to force to HTTPS and getting too many redirects with the below in .htaccess file. Based on my research on Stack, this should work. Cleared cache, cookies, all that.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
Ok, figured it out. Because I'm behind a load balancer, I had to replace:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
WITH:
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,QSA]
More info on why you need that header here: Load Balancers and HTTPS
I had a similar problem (with Codeigniter and using AWS Classic ELB) but the above solution did not work for me. I had to apply the rewrite conditions and rules in the https.conf file and then restart the apache server. See here for how to do it. Also worth noting that AWS don't recommend the .htaccess approach (not sure why):
https://aws.amazon.com/premiumsupport/knowledge-center/redirect-http-https-elb/
https://www.youtube.com/watch?v=hvqZV_50GlQ
I had a similiar problem with Laravel 6 on a shared hosting. When I configured CPanel to redirect my app to a secure https url, it kept redirecting infinitely.
I had this in my .htaccess
RewriteCond %{HTTP_HOST} ^biblioteca\.vallenateca\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.biblioteca\.vallenateca\.com$
RewriteRule ^/?$ "https\:\/\/biblioteca\.vallenateca\.com" [R=301,L]
I added this two lines.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteCond %{HTTP_HOST} ^biblioteca\.vallenateca\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.biblioteca\.vallenateca\.com$
RewriteRule ^/?$ "https\:\/\/biblioteca\.vallenateca\.com" [R=301,L]
And it solved it.
In laravel 8, the default on the .htaccess file is:
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
This worked for me and I'm using Inmotion hosting:
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,QSA]

laravel ERR_TOO_MANY_REDIRECTS after adding SSL

so i am using cloudways with digitalocean and now trying to add letsencrypt into my laravel 5.4 web app...
and according to tech support in cloudways they say i need to modify my .htaccess to be like this
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
but after that i got
ERR_TOO_MANY_REDIRECTS
what's gone wrong? cloudways tech support can't give any solution either... so i kinda stuck in here
i also do some research before and read that i need to add
If(env(' APP_ENV') !== 'local') { $url->forceSchema('https'); }
into app/Providers/AppServiceProvider.php in boot function to make all request to be https....
but still no luck...
okay so i already got the solution, i forgot that my site also have cloudflare cdn and in crypto part it set SSL to Full mode, just change it to flexible one and everything works great....

301 redirect non-www to www not always working

I've read through a ton of posts and pages trying to figure this out. I have it mostly working. I have a .htaccess file setup and I'm trying to redirect (301) any page in my site from non-www to www version.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
It seems to work from the base url. However, it doesn't redirect for sub pages.
This works:
example.com -> www.example.com
This does NOT work:
example.com/foo.html -> www.example.com/foo.html
Any help would be much appreciated
I think you need to add a \ to escape the dot in your domain (line 2).
As in:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(.*)\.yourdomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]
...as seen here: http://www.hostingdiscussion.com/promotion-marketing/26083-301-redirect-non-www-www-vice-versa-good-search-engine-optimization-technique.html
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Here's my rule that work in my prod environment:
# If domain name without "www", add them:
RewriteCond %{HTTP_HOST} ^mydomainname\.(fr|com|net|org|eu) [NC]
# without www => force redirection:
RewriteRule (.*) http://www.mydomainname.%1$1 [QSA,R=301,L]

Resources