====== 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 == Redirect 301 /d/file.html /ddd/file.html == Redirect entire site to new domain == Redirect 301 / http://www.domain.com == Redirect site to HTTPS == RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} == Redirect all non-domain names to the domain == RewriteEngine On RewriteCond %{HTTP_HOST} !^www.domain.com RewriteRule (.*) http://www.domain.com$1 [R=301,L] Same with not specifying a specific domain -- works for virtual hosts: RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] == Redirect non-www prefix for a domain to www == RewriteCond %{HTTP_HOST} ^example.com RewriteRule (.*) http://www.example.com/$1 [R=301,L] == Rewrite if REQUEST_URI matches string == You can use Perl regular expression syntax with RewriteCond RewriteEngine On RewriteCond %{REQUEST_URI} ^/(dmc)?wiki RewriteRule ^(.*)$ https://nx.beandog.org/$1 ==== Access ==== == Allow access from subnet only == Order Deny,Allow Deny from all Allow from 192.168.1.0/24 == Require either user authentication or subnet access == The ''DirectoryMatch'' here restricts access to ''*-dev'' sites: 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