Skip to content

Instantly share code, notes, and snippets.

@Jesm
Last active January 21, 2016 17:48
Show Gist options
  • Save Jesm/dd64d101f01052e66faa to your computer and use it in GitHub Desktop.
Save Jesm/dd64d101f01052e66faa to your computer and use it in GitHub Desktop.
Just some trivial tasks to do with .htaccess
<IfModule mod_rewrite.c>
# Redirect to another domain
RewriteCond %{HTTP_HOST} ^example\.com$ [NC] # Here goes the regex to match the domain that will be redirected
RewriteCond %{HTTP_HOST} ^(www\.)?example\.net$ [NC] # Create a new condition for every domain, if possible
RewriteRule ^(.*)$ http://www.example.it/$1 [R=301,NC,L]
# Force redirect to www
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,NC,L]
</IfModule>
# Prevent directory listing
Options -Indexes
# HTTP authentication
SetEnvIfNoCase Host example\.com$ require_auth=true # Define here the domain that should be authenticated
AuthType Basic
AuthName "Authentication message" # The message that appears to the user
AuthUserFile /home/example/site/.htpasswd # Set here the absolute path to htpasswd file
Order Deny,Allow
Deny from all
Satisfy any
Require valid-user
Allow from env=!require_auth
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment