1

A weird request, but I really need this answered. Can you guys help me using re-write rules to remove the trailing slash from urls in Lighttpd.conf?

EG:

**A** www.example.com/page/
**B** www.example.com/page

I want url A to be forced into the semantics of url B.

Thank you very much.

3 Answers 3

1

What you are trying to do sounds wrong. The web-server does not handle the request urls that the browser sees. This is an application issue. Your web-application needs to present the urls in the form of www.example.com/page instead of www.example.com/page/ that it does now.

If you do not want to change the application but still want this desired behaviour, you may want to consider using a filtering proxy in front of lighty and then filtering all the returned links.

1
  • The trouble is if you don't have a web application, and you're just serving static files. Then URLs are indeed entirely the server's responsibility. May 17, 2018 at 16:04
0

Not really to the point, but you might want to have the reverse effect...

Anyways, as far as lighttpd code goes, that would be something like this:

url.redirect = ( "/page/" => "/page" )
url.rewrite-once = ( "/page" => "/page/" )

but, since "/page" doesn't find a file and tries the directory "/page/" (and the rewrite seems to do nothing to hide that), that does produce a redirect-loop.

Then your real question would be: is it possible to tell lighttpd not to redirect on directories? That, unfortunately, I didn't find a way to do... but I didn't search in deep, in fact I do prefer URLs with trailing slashes (also visually)...

0

Suppose you want the request /foo/bar to serve /foo/bar/index.html, and /foo/bar/ to redirect to /foo/bar. Then you can say:

url.redirect = ("^/foo/bar/$" => "/foo/bar")
url.rewrite-once = ("^/foo/bar$" => "/foo/bar/index.html")

Rewriting directly to the index file instead of to /foo/bar/, and anchoring the redirect regex with $, avoids triggering the redirect rule after the rewrite.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .