| Status | Definition |
|---|---|
| 301 | Moved permanently |
| 307 | Temporary redirect |
Redirect 301 /d/file.html /ddd/file.html
Redirect 301 / http://www.domain.com
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
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]
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
You can use Perl regular expression syntax with RewriteCond
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/(dmc)?wiki
RewriteRule ^(.*)$ https://nx.beandog.org/$1
Order Deny,Allow Deny from all Allow from 192.168.1.0/24
The DirectoryMatch here restricts access to *-dev sites:
<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>