Skip to content

Instantly share code, notes, and snippets.

@xikaos
Forked from Jesm/.htaccess
Last active April 13, 2016 18:31
Show Gist options
  • Save xikaos/4129b68e64c698975a1c to your computer and use it in GitHub Desktop.
Save xikaos/4129b68e64c698975a1c 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
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,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