# Another way to get rid of the trailing slash \`/\` in URL?

**URL:** <https://forums.realmacsoftware.com/t/another-way-to-get-rid-of-the-trailing-slash-in-url/34944>\
**Category:** RapidWeaver Classic\
**Created:** [September 26, 2020, 3:29pm UTC](https://forums.realmacsoftware.com/t/another-way-to-get-rid-of-the-trailing-slash-in-url/34944 "2020-09-26T15:29:55Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![OmarKN](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/omarkn/32/14654_2.png) [@OmarKN](https://forums.realmacsoftware.com/u/OmarKN)\
**Post date:** [September 26, 2020, 3:29pm UTC](https://forums.realmacsoftware.com/t/another-way-to-get-rid-of-the-trailing-slash-in-url/34944/1 "2020-09-26T15:29:55Z")

</div>

Is there another way to get rid of the trailing slash `/`

There is this .htaccess rule:

```auto
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R] # <- for test, for prod use [L,R=301]

```

This one didn’t work either:

To complement Jon Lin’s answer, here is a no-trailing-slash technique that also works if the website is located in a directory (like [example.org/blog/](http://example.org/blog/)):

```auto
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [R=301,L]

```

from [http://stackoverflow.com](https://stackoverflow.com/questions/21417263/htaccess-add-remove-trailing-slash-from-url)  
both don’t work.

---

<div class="post-metadata">

**Author:** ![teefers](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/teefers/32/8173_2.png) [@teefers](https://forums.realmacsoftware.com/u/teefers)\
**Post date:** [September 26, 2020, 7:22pm UTC](https://forums.realmacsoftware.com/t/another-way-to-get-rid-of-the-trailing-slash-in-url/34944/2 "2020-09-26T19:22:51Z")

</div>

Why do you want to remove the trailing slash?

It’s common for URLs with a trailing slash to indicate a directory, and those without a trailing slash to denote a file. URL’s without a trailing slash or an extension just don’t look right.

In the case of tidy links the addresses end up at the same location. For example [The Best Mac Website Builder - RapidWeaver Classic](https://www.realmacsoftware.com/rapidweaver/) and [The Best Mac Website Builder - RapidWeaver Classic](https://www.realmacsoftware.com/rapidweaver) will both go to the same URL. The Web server knows that even a technically incomplete address (a URL that ends with a folder name only) needs the trailing slash. Click on [The Best Mac Website Builder - RapidWeaver Classic](https://www.realmacsoftware.com/rapidweaver) and then look at the address bar. The trailing slash has been added.

> [@OmarKN](#):
>
> from [http://stackoverflow.com](https://stackoverflow.com/questions/21417263/htaccess-add-remove-trailing-slash-from-url)  
> both don’t work.

Stackoverflow is probably the largest technical forum on the internet without a link to the post you are using it’s hard for anyone else to see what the author(s) might be talking about.

I think this is the post you are talking about:  
[php - Htaccess: add/remove trailing slash from URL - Stack Overflow](https://stackoverflow.com/questions/21417263/htaccess-add-remove-trailing-slash-from-url)

Both solutions offered above do work. They both will remove the trailing slash from a URL. The problem is when you use tidy links you aren’t providing a complete URI, you aren’t giving the filename portion of the URL. So when either of the above options executes, they will remove the trailing slash.

So in my example URL above  
`https://www.realmacsoftware.com/rapidweaver/`  
Will become:

`https://www.realmacsoftware.com/rapidweaver`

Next, Apache (or Nginx) will then get a URL that doesn’t end with a `/` indicating it’s a directory (folder) and it’s not a file name. It could issue a 404 (not found) but it also knows that it has a directory with that name. So a 301 redirect will get issued. Back to:

`https://www.realmacsoftware.com/rapidweaver/`

Now the webserver has a directory name, It knows that if it has a request for a directory without a file name to look for files with certain names that are in that directory.

A typical Apache DirectoryIndex Directive:

```auto
DirectoryIndex index.html index.php index.cgi

```

The Webserver will then look from left to right for a file in that directory until it finds one that matches the name or it will then issue a 404.

So both solutions given above do strip off the trailing slash. You can paste either one of them into [https://htaccess.madewithlove.be/](https://htaccess.madewithlove.be/) an excellent htaccess file tester. (the first one you’ll need to remove the comments as `#` isn’t at the beginning of a line). And you can see that the Output URL is returned without the trailing `/`.

But as you have discovered the webserver adds it back in.

---

<div class="post-metadata">

**Author:** ![OmarKN](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/omarkn/32/14654_2.png) [@OmarKN](https://forums.realmacsoftware.com/u/OmarKN)\
**Post date:** [September 26, 2020, 8:37pm UTC](https://forums.realmacsoftware.com/t/another-way-to-get-rid-of-the-trailing-slash-in-url/34944/3 "2020-09-26T20:37:24Z")

</div>

Alright, I see your (the) point.

‚ and probably I’ll have to settle with the hard truth of internet web servers.

(and I checked it with [madewithlove.be](https://htaccess.madewithlove.be/) and yes the slash was added back again.)

* * *

But there are plenty of pages out there, which don’t finish with a / slash, f ex:

[www.kurser.se/kurs/dans](https://www.kurser.se/kurs/dans)

/

with best regards, Omar KN, Stockholm, Sweden

---

<div class="post-metadata">

**Author:** ![teefers](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/teefers/32/8173_2.png) [@teefers](https://forums.realmacsoftware.com/u/teefers)\
**Post date:** [September 26, 2020, 9:03pm UTC](https://forums.realmacsoftware.com/t/another-way-to-get-rid-of-the-trailing-slash-in-url/34944/4 "2020-09-26T21:03:05Z")

</div>

> [@OmarKN](#):
>
> www.kurser.se/kurs/dans

in this example the web servers is ` Microsoft-IIS/10.0` and the file name is actually `dans`.

BTW: IIS (aka Windows Server) is a totally different beast.

---

<div class="post-metadata">

**Author:** ![OmarKN](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/omarkn/32/14654_2.png) [@OmarKN](https://forums.realmacsoftware.com/u/OmarKN)\
**Post date:** [September 28, 2020, 3:45pm UTC](https://forums.realmacsoftware.com/t/another-way-to-get-rid-of-the-trailing-slash-in-url/34944/5 "2020-09-28T15:45:21Z")

</div>

A related issue 🙂

When scanning for broken links etc. there are quite a few links with double `//` - like this:

[https://www.livingislam.org//humankind/man-and-woman/](https://www.livingislam.org//humankind/man-and-woman/)

[https://www.livingislam.org//english.html](https://www.livingislam.org//english.html)

What is the cause of this double slash?

/

with best regards, Omar KN, Stockholm, Sweden

---

<div class="post-metadata">

**Author:** ![Mathew](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/mathew/32/2771_2.png) [@Mathew](https://forums.realmacsoftware.com/u/Mathew)\
**Post date:** [September 28, 2020, 3:57pm UTC](https://forums.realmacsoftware.com/t/another-way-to-get-rid-of-the-trailing-slash-in-url/34944/6 "2020-09-28T15:57:58Z")

</div>

That’s standard operating business for web links. It’s rare that you don’t see this! For example the link to this particular thread is:

```auto
http://forums.realmacsoftware.com/t/another-way-to-get-rid-of-the-trailing-slash-in-url/34944/5

```

I would not call this a “related issue”. It’s how the web works.

---

<div class="post-metadata">

**Author:** ![teefers](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/teefers/32/8173_2.png) [@teefers](https://forums.realmacsoftware.com/u/teefers)\
**Post date:** [September 28, 2020, 5:08pm UTC](https://forums.realmacsoftware.com/t/another-way-to-get-rid-of-the-trailing-slash-in-url/34944/7 "2020-09-28T17:08:07Z")

</div>

> [@OmarKN](#):
>
> When scanning for broken links

Not sure what you are using to scan, but both links above work, so they aren’t broken.

The URL ( Uniform Resource Locators) standards were defined in [RFC](https://en.wikipedia.org/wiki/RFC_(identifier)) [1738](https://tools.ietf.org/html/rfc1738)). Every HTTP URL conforms to the syntax of a generic URI. The URI consists of

> scheme:[//authority]path[?query][#fragment]

The double slashes you see in the example URL’s above would be considered part of the path. The path is made up of a sequence of path segments separated by a slash ( `/` ).

> A segment may also be empty, resulting in two consecutive slashes ( `//` ) in the path component.

---

<div class="post-metadata">

**Author:** ![OmarKN](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/omarkn/32/14654_2.png) [@OmarKN](https://forums.realmacsoftware.com/u/OmarKN)\
**Post date:** [September 28, 2020, 5:46pm UTC](https://forums.realmacsoftware.com/t/another-way-to-get-rid-of-the-trailing-slash-in-url/34944/8 "2020-09-28T17:46:05Z")

</div>

> [@teefers](#):
>
> Not sure what you are using to scan

Integrity app by PeacockMedia

> [@teefers](#):
>
> … both links above work, so they aren’t broken.

Right they aren’t broken, but it does look a bit unusual (with 2 slashes).

> A segment may also be empty, resulting in two consecutive slashes ( `//` ) in the path component.

Maybe this is the reason?!

/okn

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/system/32/25301_2.png) [@system](https://forums.realmacsoftware.com/u/system)\
**Post date:** [October 29, 2020, 3:46am UTC](https://forums.realmacsoftware.com/t/another-way-to-get-rid-of-the-trailing-slash-in-url/34944/9 "2020-10-29T03:46:08Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
