Forward Slash at end of CSS url breaks

I am developing a website and when I put a forward slash /

at the end the URL

CSS file is not readable.

Example:

  • This url works fine: www.localhost.com/index.php

  • This URL ignores the CSS file: www.localhost.com/index.php/

In short, the forward slash ruins the design of the website.

Does anyone know how to fix this problem? I was looking for a solution .htaccess

but it doesn't work.

+3


source to share


4 answers


try including your css file using an absolute path (for example http://...

) or a path starting from your website (for example /css/yourfile.css

)



otherwise you need to deny (or redirect) requests to index.php/

in index.php

via .htaccess (or server config)

+3


source


This will remove the trailing slash, excluding root and existing folders.



RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)(\.php|\.html)/$  /$1$2 [R=301,L]

      

+1


source


Just use "/" before setting css location in index.html header.

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

      

This way your index.html will look for the file from the root directory.

+1


source


just add full url of css files

And also use full path for all href links in this php page for example, just don't add <a href="home.html">

instead<a href="http://domain/home.html

0


source







All Articles