Welcome! Log In Create A New Profile

Advanced

why that rewrite rule enforces trailing slash

Posted by m_abdelfattah 
why that rewrite rule enforces trailing slash
April 26, 2015 01:29PM
I've the following rewrite rule on location /, and it enforces trailing slash!

location / {
rewrite ^(\/.*) https://example.com/ar$1 permanent;
}

each, time I curl mydomain.com, I got the following response:
HTTP/1.1 301 Moved Permanently
Content-Type: text/html
Connection: keep-alive
Location: https://example.com/ar/


I do not want the trailing slash at the end of the redirected URL!



Edited 1 time(s). Last edit at 04/26/2015 01:32PM by m_abdelfattah.
Re: why that rewrite rule enforces trailing slash
April 26, 2015 01:46PM
http://stackoverflow.com/questions/18422092/how-to-remove-trailing-slash-from-url-in-nginx-only-if-directory-doesnt-exist
www.nginxtips.com/nginx-remove-trailing-slash/

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: why that rewrite rule enforces trailing slash
April 26, 2015 02:05PM
I don't think that stackoverflow question is related to mine! I don't have a redirect loop! and my root directive is outside my location block!
Re: why that rewrite rule enforces trailing slash
April 26, 2015 02:25PM
$1 at least has a slash.

map $request_uri $requri {
default $request_uri;
/ "";
}

[...]

rewrite ^(\/.*) https://example.com/ar$requri permanent;

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: why that rewrite rule enforces trailing slash
April 26, 2015 02:49PM
Thank you itpp2012, but is there a reference for "$1 at least has a slash" ? Or people get it by practice :) ?!
Re: why that rewrite rule enforces trailing slash
April 26, 2015 03:20PM
Mostly by practice :)

Just make a number of test location blocks and see which one works, then figure out a mapping to prevent using if's.

---
nginx for Windows http://nginx-win.ecsds.eu/
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 122
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready