I am coding a portal which has multi categories.
Example:
http://localhost/portal/cats
http://localhost/portal/dogs
Ofcourse this is possible with URL rewrite
Like this
RewriteRule ^cats$ /portal/index.php?cat=cats
Ok so this works alright.
Problem happens when I try to access page like this
http://localhost/portal/cats/black-cat-22
My url rewrite is:
RewriteRule ^cats/(.*)-([0-9]+)$ /portal/page.php?cat=cats&id=$2
Why?
Because all my CSS & image files are located in http://localhost/portal/elements and not in http://localhost/portal/cats/elements – which is not even real directory.
So I am looking for solution how to do rewrite if URL includes /elements/ it reads from /portal/elements not from any other directory.
If something is unclear, free to ask below.
Cheers and happy new year.
That’s where the html
<base>tag comes to the rescue 🙂Add something like this as first line in your HTML head:
Then everything you reference with relative URLs will be relative to that base.
So you can reference your CSS using:
Which should resolve to:
http://localhost/portal/elements/stylesheet.css, no matter what URL you’re currently visiting (be thatportal/cats, orportal/cats/some-black-catetc.