How to take "/" from the end of a server folder?

Asked

Viewed 720 times

1

It’s like this: I have a contact folder on my website, which appears like this: www.meusite.com/contact/ , and how do I get it to appear www.meusite.com/contact ? But it has to be just by folder. Thank you.

1 answer

1

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    DirectorySlash off
    RewriteRule ^(.*)\/(\?.*)?$ $1$2 [R=301,L]
</IfModule>

Remembering that you will have to have the module mod_rewrite Apache-enabled.


Important remark:

It’s not a good idea to link a website directory without the last /.

  • Because it is semantically incorrect to induce that the link should be a file with no extension instead of a directory:
    www.meusite.com/contact/ : directory
    www.meusite.com/contact : file

  • There is a www.meusite.com/contact redirection to www.meusite.com/contact/, when the server realizes that it is the directory "contact".

  • Server error 404 may occur.

More details on Linking Issues: Why a Trailing Slash in the URL Does Matter.

  • It would have to elaborate the 1st topic (mere curiosity, just wanted to understand your point of view) "is semantically incorrect when inducing that the link should be a file without extension instead of a directory" I agree 100% with the automatic addition (or subtraction) being an error (after all with or without bar are "100% different" Urls). But what would be the real problem if, for example, an entire site served only Urls without bar at the end, for example?

  • PS: It is not a challenge, it is mere curiosity. And when I speak of elaborate, I say only one comment. The main answer already ta OK in my view.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.