Trailing Slash redirection poblem

Dear All,
Need some help to remove trailing Slash.
I have been trying to remove the trailing slash with this redirection
rule.
rewrite ^/(.*)/$ /$1 permanent;

however it is creating a loop.

curl -I https://xxxx.com/live/

HTTP/1.1 301 Moved Permanently
Server: nginx/1.6.2
Date: Sat, 30 Apr 2016 07:39:07 GMT
Content-Type: text/html
Content-Length: 184
Location: https://xxxx.com/live
Connection: keep-alive

curl -I https://xxxx.com/live

HTTP/1.1 301 Moved Permanently
Server: nginx/1.6.2
Date: Sat, 30 Apr 2016 07:39:29 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Location: https://xxxx.com/live/

Can you please guide what i am doing wrong here.

Thanks,
Yousuf

The configuration you have shown says “if the request is for /live/,
ask the browser to instead request /live”.

The configuration you have not shown says “if the request is for /live,
ask the browser to instead request /live/”.

Thanks for the tip I think I got the problem but could not resolve it.
try_files $uri $uri.html $uri/ /index.php?q=$request_uri;
I even tried deleting “$uri.html $uri/” but still creating loop. I know
this is a important line to display wordpress pages . now the error
turn
404 from redirection loop.

You should not have both of those in the same configuration file, or
you get a loop.

Yes I got this now as shared. Thanks for the tip again.

The not-shown configuration is usually a very good idea if “/live”
is to be served from the filesystem and corresponds to a directory.

So: why do you want to remove the trailing slash, in the shown
configuration?
Actually this is a requirement from my client.

If you want /live to redirect to /live/, then you should configure thing
such that /live/ does not redirect to /live.

No I want /live/ to be redirected to /live and the rule which is
redirecting /live to /live/ and ending up as loop Is also important.
Any
helpful advice is highly appreciated.

On Sat, Apr 30, 2016 at 12:47:20PM +0500, Muhammad Yousuf K. wrote:

Hi there,

I have been trying to remove the trailing slash with this redirection rule.
rewrite ^/(.*)/$ /$1 permanent;

however it is creating a loop.

curl -I https://xxxx.com/live/

HTTP/1.1 301 Moved Permanently
Location: https://xxxx.com/live

curl -I https://xxxx.com/live

HTTP/1.1 301 Moved Permanently
Location: https://xxxx.com/live/

Can you please guide what i am doing wrong here.

The configuration you have shown says “if the request is for /live/,
ask the browser to instead request /live”.

The configuration you have not shown says “if the request is for /live,
ask the browser to instead request /live/”.

You should not have both of those in the same configuration file, or
you get a loop.

The not-shown configuration is usually a very good idea if “/live”
is to be served from the filesystem and corresponds to a directory.

So: why do you want to remove the trailing slash, in the shown
configuration?

If you want /live to redirect to /live/, then you should configure thing
such that /live/ does not redirect to /live.

f

Francis D. [email protected]

just want to make it more clear that when i comment out this line
#try_files
$uri $uri.html $uri/ /index.php?q=$request_uri; error become 404 from
redirection loop error.

On Sun, May 1, 2016 at 1:16 PM, Muhammad Yousuf K. [email protected]

So these opposite redirection rules are fighting each other and are the
source of your problem, which Francis helped you to alleviate.

Sit back, grab an erasable whiteboard, scratch your head and think about
your website’s design: both rules probably have their use in their own
corner, but you shall not have them activated at the same spot at any
given
time, as it will result in an infinite loop: a computer does exactly
what
you tell it to do. There is nothing stupider than that.
The problem lies between the desk and the chair. ;o)

​Do not merely copy-paste pre-cooked Wordpress-hypothetically-ready
configuration directives​. Try to recreate it by hand, understanding the
use and intention of every line.
nginx docs http://nginx.org/en/docs/ will most probably come helpful.

Enjoy learning! :o)

B. R.

On Sun, May 1, 2016 at 10:18 AM, Muhammad Yousuf K. [email protected]

first of all my apologies if i question something inapplicable , this
could be the result of my less knowledge in nginx. i hope you guys don’t
mind.

Thanks for the reply, actually we have 5 categories. and then we have
hundred plus post in each category. now when user click on our category.
he
sees intro about the category and then list of all posts.
when user click on catagory it open up like this
https://xxxx.com/catagory/

and when post is clicked it opens up like this
https://xxxx.com/catagory/posts.html

but now what client want is when some one open up the category it should
open up like this.
https://xxxx.com/catagory (with out trailing slash)

This is all what they want.

Thanks,
Yousuf

On Mon, May 02, 2016 at 05:48:12PM +0500, Muhammad Yousuf K. wrote:

Hi there,

Thanks for the reply, actually we have 5 categories. and then we have
hundred plus post in each category. now when user click on our category. he
sees intro about the category and then list of all posts.
when user click on catagory it open up like this
https://xxxx.com/catagory/

It sounds to me like that is an internal-to-wordpress thing, so you
may be better off removing any clever nginx config and just configure
wordpress to create the links that you want it to create.

(I do not know if it possible to configure wordpress like that.)

and when post is clicked it opens up like this
https://xxxx.com/catagory/posts.html

but now what client want is when some one open up the category it should
open up like this.
https://xxxx.com/catagory (with out trailing slash)

When someone clicks on catagory, they are following a link in whatever
html was returned from their previous request. If that link has a
trailing
slash, they’ll ask for the trailing slash.

If the content on the catagory page contains links like “post1.html”,
then you will need the trailing slash – or you will need to change
the content to be of the form “catagory/post1.html”. That should all be
configurable within wordpress, if anywhere.

Good luck with it,

f

Francis D. [email protected]

On Sun, May 01, 2016 at 01:16:51PM +0500, Muhammad Yousuf K. wrote:

Hi there,

The configuration you have shown says “if the request is for /live/,
ask the browser to instead request /live”.

The configuration you have not shown says “if the request is for /live,
ask the browser to instead request /live/”.

Thanks for the tip I think I got the problem but could not resolve it.

If you make the request for “/live”, what response do you actually want?

The contents of some file? The output of wordpress being given some
arguments? Be as specific as possible, and it is much more likely that
you will understand how nginx needs to be configured to do that.

So: why do you want to remove the trailing slash, in the shown
configuration?
Actually this is a requirement from my client.

Sometimes, the correct response to a client requirement is “no”.

It is not yet clear to me whether this is one of those times.

f

Francis D. [email protected]

Thanks for the info. will check on that.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs