2
0
Fork 0
mirror of https://github.com/phanan/htaccess.git synced 2018-11-08 13:39:40 +01:00

Merge branch 'alexweissman-master'

This commit is contained in:
An Phan 2015-02-10 23:10:34 +08:00
commit b9a6f3584d

View file

@ -17,7 +17,9 @@ What I'm doing here is mostly collecting useful snippets from all over the inter
- [Force HTTPS Behind a Proxy](#force-https-behind-a-proxy)
- [Force Trailing Slash](#force-trailing-slash)
- [Redirect a Single Page](#redirect-a-single-page)
- [Alias a Single Directory](#alias-a-single-directory)
- [Redirect an Entire Site](#redirect-an-entire-site)
- [Alias Clean URLs](#alias-clean-urls)
- [Security](#security)
- [Deny All Access](#deny-all-access)
- [Deny All Access Except Yours](#deny-all-access-except-yours)
@ -94,12 +96,27 @@ Redirect 301 /oldpage2.html http://www.yoursite.com/folder/
```
[Source](http://css-tricks.com/snippets/htaccess/301-redirects/)
### Alias a Single Directory
``` apacheconf
RewriteEngine On
RewriteRule ^source-directory/(.*) target-directory/$1
```
### Redirect an Entire Site
``` apacheconf
Redirect 301 / http://newsite.com/
```
This way does it with links intact. That is `www.oldsite.com/some/crazy/link.html` will become `www.newsite.com/some/crazy/link.html`. This is extremely helpful when you are just "moving" a site to a new domain. [Source](http://css-tricks.com/snippets/htaccess/301-redirects/)
### Alias "Clean" URLs
This snippet lets you use "clean URLs" -- those without a PHP extension, e.g. `example.com/users` instead of `example.com/users.php`.
``` apacheconf
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^.]+)$ $1.php [NC,L]
```
[Source](http://www.abeautifulsite.net/access-pages-without-the-php-extension-using-htaccess/)
## Security
### Deny All Access
``` apacheconf