I'm using a MVC model and I can invoke webpages with URLs like http://mywebsite.com/product/productid.html
.
My folder structure is the following:
- views - the views folder
- js - the javascript and jquery folder
- css - the stylesheets folder
- images - the images folder
In views folder are contained web pages used to show data to the users. They can include scripts, images and stylesheets. The following snippet is incorrect
<link rel="stylesheet" href="css/style.css" media="all" type='text/css' />
since the webpage is called with the URL above, and css can't be found with a relative path. To solve the problem, I have defined a DOMAIN
variable in PHP and changed the code into
<link rel="stylesheet" href="<?php echo DOMAIN;?>css/style.css" media="all" type='text/css' />
This works, but forces me to add the <?php echo DOMAIN;?>
snippet to each href
and src
attribute on each page. Is it possible to automate it? I've tought to use the :before
selector but I don't have idea how to use it in this case.
Any ideas? Thanks in advance.