Search code examples
urlwebslash

How to remove or disable the slash at the end of the URL?


I don't know exactly what is the problem, but I have done a lot of research about trailing slash in PHP.

My problem is that when I visit my site I always see trailing slash and it causes all the resources to fail to load.

How do I disable trailing slash that's being added in .htaccess. Thanks!


Solution

  • PHP does not add / to URLs by default, it's your script doing that.

    If you want to use the style.css regardless, use the absolute or the full path - so if your style.css is on http://domain.com/style.css, then you can either use

    <link rel="stylesheet" type="text/css" href="/style.css">
    

    or

    <link rel="stylesheet" type="text/css" href="http://domain.com/style.css">
    

    With your file.php thing, it looks in http://domain.com/file.php/style.css, while either of the above uses the file you created at http://domain.com/style.css.

    That would as well work for http://domain.com/folder/file.php - simply use /folder/style.css in the href-tag or, once again, the full URL to it.