Skip to content

Instantly share code, notes, and snippets.

@farukcam
Forked from iPublicis/.htaccess
Created November 15, 2020 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save farukcam/9d3de4ba89ab7236c5b428d55e5a93c8 to your computer and use it in GitHub Desktop.
Save farukcam/9d3de4ba89ab7236c5b428d55e5a93c8 to your computer and use it in GitHub Desktop.
NODE.JS app in Apache - force www. and https: sample .htaccess - partialy based on vielhuber/.htaccess
#########################
#
# NODE.JS app running in Apache
# sample .htaccess - partialy based on vielhuber/.htaccess
# Also rules to enforce www. prefix and https: SSL access
#
# This file must be on the dir where Apache expects to find the website
# The Node App can be anywhere else but must be accessible as explained below.
#
# ModRewrite must be active on Apache
RewriteEngine On
# First check if domain starts with www. and add it
# then if not using SSL force it
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L,NE]
# Redirect all trafic to NODE.JS server.
# It must be running and, in this case, listening to port 60000
RewriteRule ^$ http://127.0.0.1:60000/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:60000/$1 [P,L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment