Reputation: 542
How do I make the following code map to the file path /my-file.php
instead of the URL path which is /projects/here
.
<link rel="stylesheet" href="inc/style.css" type="text/css" media="screen">
This line attempts to include the file /projects/inc/style.css
which does not exist when it should include the file /inc/style.css
.
I have used my .htaccess
file to redirect /my-file.php
to /projects/here
which is then mapped back to /my-file.php
to create a 'clean' URL.
I don't want to have to use ../
as in my particular set-up (this is a simplified version) it would create more work than should be necessary. I expect this will need PHP somehow.
Thanks in advance!
Upvotes: 2
Views: 664
Reputation: 542
What I chose to do was to set a variable that when set, PHP will set another variable to ../
and I put <?php echo $var; ?>
just before the link and so $var
is ../
and will thus solve this issue. This could be changed to use the absolute URL at any time, but this fits with my criteria.
In other words, just before every relative URL (that causes an issue - a minority), I have added <?php echo $var; ?>
and so if I set the correct variable at the beginning of the page which points out that this page is a subdirectory, then $var
is set to ../
which means that it will be pointing to the correct file to include.
This is by no means an ideal answer, but for my particular situation, this is what I was required to do.
Much thanks to the following answer (which I upvoted) which helped me come to this conclusion (but did not forfill my critera): How map html/css included files to file root not URL path
Upvotes: 0
Reputation: 46900
Why take so much pain and implement a redirect or rewrite. You can simply provide the absolute url of your css file.
<link rel="stylesheet" href="http://www.yourwebsite.com/inc/style.css" type="text/css" media="screen">
Upvotes: 1