Welcome Guest, Not a member yet? Register   Sign In
URI with Slash

I have set the base url set to be 'http://domainname/public/'.  The links to css and js files are <link href="assets/css/..." rel="stylesheet">. Everything works well until I try to access a page with a slash in it, e.g. 'http://domainname/product/1'.  Now the path to the css and js becomes 'http://domainname/product/assets/css/...'.  The css and js files can't be found.
Why does this happen?

The current URI: http://domainname/product/1
HTML: <link href="assets/css/..." rel="stylesheet">

"assets/css/..." is a relative path, so it means "http://domainname/product/assets/css/...".

PHP Code:
<link href="<?= base_url('assets/css/...');?>" rel="stylesheet"
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

(This post was last modified: 05-29-2023, 05:06 AM by LieoUhlerredyh.)

This happens because when you access a page with a slash in it, the browser treats it as a subdirectory of the base URL 'http://domainname/public/'. As a result, the browser looks for the CSS and JS files in the wrong directory.

To fix this, you can use an absolute path for the links to the CSS and JS files, instead of a relative path. Instead of using <link href="assets/css/..." rel="stylesheet">, you can use <link href="/public/assets/css/..." rel="stylesheet">. This will ensure that the browser always looks for the files in the correct directory, regardless omegle of the URL of the current page.

Theme © iAndrew 2016 - Forum software by © MyBB