Skip to content

Instantly share code, notes, and snippets.

@jimmi-joensson
Last active January 14, 2019 21:36
Show Gist options
  • Save jimmi-joensson/28866b8005ccc4724d84d7d9e31bf0ee to your computer and use it in GitHub Desktop.
Save jimmi-joensson/28866b8005ccc4724d84d7d9e31bf0ee to your computer and use it in GitHub Desktop.
.htaccess parts
Options -Indexes
# .htaccess primary domain to web redirect
# this file must be in the (public_html | web ) folder of your hosting account
# make the changes to the file according to the instructions.
<IfModule mod_rewrite.c>
# Do not change this line.
RewriteEngine on
#*************************************
# Load images from external site *
#*************************************
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^assets/(.*\.(gif|jpg|png)) http://www.website.com/assets/$1 [L,R]
#*************************************
# Exclude rule for selected URLs *
#*************************************
RewriteCond %{THE_REQUEST} !/part_of_url/ [NC]
#*************************
# Force https and www *
#*************************
# ensure www on urls without subdomains
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
# ensure https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#*****************************
# Force https and non-www *
#*****************************
# ensure non-www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
# ensure https
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
#************************************
# Redirect solution to subfolder *
#************************************
# Change DOMAIN.com to be your primary domain.
RewriteCond %{HTTP_HOST} ^(www.)?DOMAIN.com$
# Change 'web' to be the folder you will use for your primary domain.
RewriteCond %{REQUEST_URI} !^/web/
#********************
# NOT RRCOMMENDED *
#********************
#
# Uncomment those two lines if you want dirs and files to be accessible out of the
# your primary domain dir.
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
# Change 'web' to be the folder you will use for your primary domain.
RewriteRule ^(.*)$ /web/$1
# Change soft-hunter.qnty.dk to be your primary domain again.
# Change 'web' to be the folder you will use for your primary domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?DOMAIN.com$
RewriteRule ^(/)?$ web/index.php [L]
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment