Skip to content

Commit

Permalink
Added Remove Trailing Slash from Arbitrary Paths
Browse files Browse the repository at this point in the history
  • Loading branch information
alexweissman authored and An Phan committed Apr 8, 2015
1 parent 3aa2d81 commit e359543
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 Trailing Slash](#force-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)
- [Alias a Single Directory](#alias-a-single-directory)
- [Alias Paths to Script](#alias-paths-to-script)
Expand Down Expand Up @@ -119,6 +120,18 @@ RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
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
``` apacheconf
Redirect 301 /oldpage.html http://www.example.com/newpage.html
Expand Down

0 comments on commit e359543

Please sign in to comment.