We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Force HTTPS

Just wanna share my .htaccess to force https

<IfModule mod_rewrite.c>
    RewriteCond %{HTTPS} !=on
    RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

    RewriteEngine on
    RewriteRule  ^$ public/     [L]
    RewriteRule  (.*) public/$1 [L]

    RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
    RewriteRule .* ? [F,L]
</IfModule>


58.3k

Hello

Can you share this tip on https://phalcontip.com

With nginx, this is way more simple.

Thanks, this might be helpful in my near future

# Redirect all non-HTTPS traffic to HTTPS
server {
listen 80;
server_name site.com www.site.com;

# Variables begin

# Destination redirect base URI
set $RURI https://www.site.com;

# Variables end

#Redirect all traffic to HTTPS WWW handler
location / {return 301 $RURI$request_uri;}
}

# Redirect non-WWW HTTPS traffic to WWW HTTPS
server {
# enable SSL with configuration defined elsewhere
listen 443 ssl;
server_name site.com;
return 301 $scheme://www.$host$request_uri;
}

# Concrete server implementation.
server {
# enable SSL with configuration defined elsewhere
listen 443 ssl;

server_name www.site.com;

# ...
# other stuff
# ....

}