I am getting a 500 Internal Server Error from my linked CSS files etc when I use this htaccess code.. Anyone know what might be the problem? I am not too fluent in htaccess yet.
Here is the code:
RewriteEngine On
RewriteBase /
RewriteRule ^(system|img|res) - [L]
RewriteRule ^picture/([^/]*)/?$ picture.php?id=$1 [L,QSA]
## The below code is something I found on the internet to remove the .php tag
# remove .php; use THE_REQUEST to prevent infinite loops
RewriteCond %{HTTP_HOST} ^www\.mywebsite\.com
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]
# remove index
RewriteRule (.*)index$ $1 [R=301]
# remove slash if not directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]
# add .php to access file, but don't redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
The URL is supposed to be: http://www.mysite.com/pictures/1 (id)
The id is always a number.
It does show me the page and I can echo the id, so that part is working, however it gives me a 500 error on linked files as mentioned above.
You’ve linked to it using a relative URI:
e.g. the
./css/text.css, and while the css file may be in the same directory aspicture.phpfile (which I assume is what is generating the content) but the browser is what actually makes the request for the CSS, not the picture.php script. The browser requests this URLhttp://www.mysite.com/picture/1, and the server internally rewrite the/picture/1to/picture.php?id=1, the browser has no clue that’s happened. So it sees the base URI as/picture/. If the browser went directly to the php file:http://www.mysite.com/picture.php?id=1, the base URI would be/and the css would resolve just fine to/./css/text.css. But the/picture/1request has a different base URI so the browser (with no clue that the base is different) blindly attempts to retrieve the css as/picture/./css/text.css, which fails because you have rules that mishandle that URI. Normally you’d just get a 404, but the rules you have after the picture rewrite mishandles the URI and returns a 500 server error.You can either add in your header:
in the content generated by
picture.php, or make the URI’s absolute: