I have the following structure on my php project:
- classes
- model.php
- views
- header.php
- footer.php
- user.php
- resources
- css
- stylesheet.css
- js
- my_javascript.js
- index.php
- controller.php
.htaccess file
RewriteEngine On
RewriteRule ^/?resources/(.*)$ resources/$1 [L]
RewriteRule ^([a-zA-Z]+)/?([a-zA-Z0-9/]*)$ index.php?page=$1&query=$2 [L]
header.php
<!DOCTYPE html>
<html>
<head>
<!-- Styles -->
<link href="resources/css/stylesheet.css" rel="stylesheet" media="screen">
</head>
<body>
The problem, as many others have mentioned on stackoverflow before (but whose solutions have not worked for me), is that Im currently redirecting all pages through index.php and therefore even my resources files, such as stylesheet.css.
1: When I ask for mydomain/user
I get the correct resources loaded with right css (mydomain/resources/css/stylesheet.css
)
2: But as Im trying to make the app RESTful, I have a page such as mydomain/user/4
and when I make a request such as this my css suddently doesn´t load. Looking at the http request its looking for (mydomain/user/resources/css/stylesheet.css
)
I have tried to solve it by including $_SERVER['DOCUMENT_ROOT']
. It does not work, and does not seem to be a "nice" solution. Thanks for your help. And yes I am a newbie at php!