no way to compare when less than two revisions

Differences

This shows you the differences between two versions of the page.


htaccess [2015/06/01 22:45] (current) – created - external edit 127.0.0.1
Line 1: Line 1:
 +====== htaccess ======
  
 +  * [[Apache]]
 +
 +  * [[https://en.wikipedia.org/wiki/List_of_HTTP_status_codes|List of HTTP status codes]]
 +  * [[http://www.askapache.com/htaccess/seo-search-engine-friendly-redirects-without-mod_rewrite.html|SEO redirects without mod_rewrite]]
 +
 +==== Redirects ====
 +
 +^ Status ^ Definition ^
 +| 301 | Moved permanently |
 +| 307 | Temporary redirect |
 +
 +== Redirect a single file ==
 +
 +<code>
 +Redirect 301 /d/file.html /ddd/file.html
 +</code>
 +
 +== Redirect entire site to new domain ==
 +
 +<code>
 +Redirect 301 / http://www.domain.com
 +</code>
 +
 +== Redirect site to HTTPS ==
 +
 +<code>RewriteEngine On
 +RewriteCond %{HTTPS} off
 +RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
 +</code>
 +
 +== Redirect all non-domain names to the domain ==
 +
 +<code>
 +RewriteEngine On
 +RewriteCond %{HTTP_HOST} !^www.domain.com
 +RewriteRule (.*) http://www.domain.com$1 [R=301,L]
 +</code>
 +
 +Same with not specifying a specific domain -- works for virtual hosts:
 +
 +<code>
 +RewriteCond %{HTTP_HOST} !^www\. [NC]
 +RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
 +</code>
 +
 +== Redirect non-www prefix for a domain to www ==
 +
 +<code>
 +RewriteCond %{HTTP_HOST} ^example.com
 +RewriteRule (.*) http://www.example.com/$1 [R=301,L]
 +</code>
 +
 +== Rewrite if REQUEST_URI matches string ==
 +
 +You can use Perl regular expression syntax with RewriteCond
 +
 +<code>RewriteEngine On
 +RewriteCond %{REQUEST_URI} ^/(dmc)?wiki
 +RewriteRule ^(.*)$ https://nx.beandog.org/$1</code>
 +
 +==== Access ====
 +
 +== Allow access from subnet only ==
 +
 +<code>
 +Order Deny,Allow
 +Deny from all
 +Allow from 192.168.1.0/24
 +</code>
 +
 +== Require either user authentication or subnet access ==
 +
 +The ''DirectoryMatch'' here restricts access to ''*-dev'' sites:
 +
 +<code>
 +<DirectoryMatch "/var/www/html/(.*\-dev)/">
 +        Order allow,deny
 +        Allow from 192.168.12.0/24
 +        AuthType Basic
 +        AuthName "Development Sites"
 +        AuthUserFile /var/www/dev-access.htpasswd
 +        Require valid-user
 +        Satisfy any
 +</DirectoryMatch>
 +</code>

Navigation
QR Code
QR Code htaccess (generated for current page)