Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the root dir of an html page?

Tags:

html

I'm in the following directory on my server:

  • http://example.nl/cms/components/

Components are in .phtml files but the extension is removed by htaccess rules.

Now I want to go to another .phtml file but then I have to write this:

<a href="../other-page/"></a>

I noticed I can also just do this:

<a href="/other-page/"></a>

But then it won't go to http://example.nl/cms/other-page/ as I want, but to http://example.nl/other-page/

How can I change the document root to "cms" so that I only have to use a single "/"?

like image 454
joostdelange Avatar asked Oct 29 '25 17:10

joostdelange


1 Answers

For absolute URLs, leading with a slash (/), the base attribute does not work.

Here is what you need for relative URLs. You need to set the meta tag basedir:

<html>
  <head>
    <base href="http://example.nl/cms/">
  </head>
  <body>
    <a href="other-page">click me</a>
  </body>
</html>

And then the browser knows that by other-page you want to link to /cms/other-page.

This is supported in all browsers as you can see.

like image 94
Phil Avatar answered Oct 31 '25 09:10

Phil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!