mirror of
https://github.com/phanan/htaccess.git
synced 2018-11-08 13:39:40 +01:00
Added Remove Trailing Slash from Arbitrary Paths
This commit is contained in:
parent
3aa2d818b0
commit
e359543c9a
1 changed files with 13 additions and 0 deletions
13
README.md
13
README.md
|
@ -18,6 +18,7 @@ What we are doing here is mostly collecting useful snippets from all over the in
|
||||||
- [Force HTTPS Behind a Proxy](#force-https-behind-a-proxy)
|
- [Force HTTPS Behind a Proxy](#force-https-behind-a-proxy)
|
||||||
- [Force Trailing Slash](#force-trailing-slash)
|
- [Force Trailing Slash](#force-trailing-slash)
|
||||||
- [Remove Trailing Slash](#remove-trailing-slash)
|
- [Remove Trailing Slash](#remove-trailing-slash)
|
||||||
|
- [Remove Trailing Slash from Arbitrary Paths](#remove-trailing-slash-from-arbitrary-paths)
|
||||||
- [Redirect a Single Page](#redirect-a-single-page)
|
- [Redirect a Single Page](#redirect-a-single-page)
|
||||||
- [Alias a Single Directory](#alias-a-single-directory)
|
- [Alias a Single Directory](#alias-a-single-directory)
|
||||||
- [Alias Paths to Script](#alias-paths-to-script)
|
- [Alias Paths to Script](#alias-paths-to-script)
|
||||||
|
@ -119,6 +120,18 @@ RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
|
||||||
RewriteCond %{REQUEST_FILENAME} !-d
|
RewriteCond %{REQUEST_FILENAME} !-d
|
||||||
RewriteRule ^(.*)/$ /$1 [R=301,L]
|
RewriteRule ^(.*)/$ /$1 [R=301,L]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Remove Trailing Slash from Arbitrary Paths
|
||||||
|
This snippet will redirect paths ending in slashes to their non-slash-terminated counterparts (except for actual directories).
|
||||||
|
E.g., `http://www.example.com/blog/` -> `http://www.example.com/blog`
|
||||||
|
This is important for SEO, since it is [recommended to have a "canonical URL" for every page](http://overit.com/blog/canonical-urls).
|
||||||
|
``` apacheconf
|
||||||
|
RewriteCond %{REQUEST_FILENAME} !-d
|
||||||
|
RewriteCond %{REQUEST_URI} (.+)/$
|
||||||
|
RewriteRule ^ %1 [L,R=301]
|
||||||
|
```
|
||||||
|
[Source](https://stackoverflow.com/questions/21417263/htaccess-add-remove-trailing-slash-from-url)
|
||||||
|
|
||||||
### Redirect a Single Page
|
### Redirect a Single Page
|
||||||
``` apacheconf
|
``` apacheconf
|
||||||
Redirect 301 /oldpage.html http://www.example.com/newpage.html
|
Redirect 301 /oldpage.html http://www.example.com/newpage.html
|
||||||
|
|
Loading…
Reference in a new issue