I try to get an \"/\" to every urls end:
example.com/art
should
example.com/art/
I use nginx as webserver.
I need the rewrite rule f
server {
# ... omissis ...
# put this before your locations
rewrite ^(/.*[^/])$ $1/ permanent;
# ... omissis ...
}
If you want some kind of requests (say other than GET
ones) to be prevented from doing this (usually it's about POST
requests, as rewrite
turns any request method into GET
, which may break some of your site's dynamic functionality), add an if
clause:
server {
# ... omissis ...
# put this before your locations
if ($request_method = "GET" ) {
rewrite ^(/.*[^/])$ $1/ permanent;
}
# ... omissis ...
}
You can also put the rewrite
in a location
block (if
too), to make it more specific.
For nginx:
rewrite ^(.*[^/])$ $1/ permanent;
Try this: ^(.*)$ http://domain.com/$1/ [L,R=301]
This redirects (Status code 301) everything ($1) without a "/" to "$1/"