Jump to content
  • Advertisement
Sign in to follow this  
Colin Jeanne

[web] Dynamic URLs

This topic is 4735 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

For a CMS I'm creating I'm implementing dynamic URLs like in this A List Apart article. Everything works perfectly but there is just something I'd like to better understand. My .htaccess file looks like this
RewriteEngine on
RewriteRule !\.(gif|jpg|jpeg|png|css)$ index.php
And the part of my index.php file which handles the dynamic URLs looks like this
// Does this file exist?
if (IsURIDynamic() == false) {
   // The file exists, simply include it
   include($_SERVER['DOCUMENT_ROOT'] . $_SERVER['REQUEST_URI']);
} else {
   // The file does not exist, the content might be dynamic
   // Output template
   require_once('template.php');
}

So if the file is a real file (that is, IsURIDynamic() returns false) it is simply included. And finally, in template.php is the following line
<link rel="stylesheet" href="organs/norm.css" type="text/css" title="Blue" />
Where organs/norm.css is the real path to the actual file. The part I dont get is that if I remove 'css' from the rewrite rule in the .htaccess file then the stylesheet is not applied to template.php. I can still view the stylesheet if I navigate to its exact location and my Apache logs tell me that it is downloaded correctly when I view template.php but it just seems to not be applied. Why is the stylesheet not applied when I include() it?

Share this post


Link to post
Share on other sites
Advertisement
Well the article says that the line

RewriteRule !\.(gif|jpg|png|css)$ /your_web_root/index.php

redirects all requests to a file index.php EXCEPT for requests for image files or CSS files. In other words: Removing the css part from the rewriterule redirects stylesheet requests to index.php, basically resulting in

<link rel="stylesheet" href="/your_web_root/index.php" type="text/css" title="Blue" />

which is of course not a valid stylesheet.

Share this post


Link to post
Share on other sites
Yes, and then when the browser reads from that address the content of the real file is returned by include(). Only the data from the CSS file is returned so I'm not sure why it's not a valid stylesheet.

Share this post


Link to post
Share on other sites
The output from any request to your index.php is sent with the default text/html MIME type. CSS stylesheets are required to be sent as text/css.

Share this post


Link to post
Share on other sites
It works fine if using .htaccess I make sure that CSS files arent redirected through my index.php I was just curious about why it didnt work when I let CSS files be redirected through index.php.

Share this post


Link to post
Share on other sites
In case you were still confused, Igni's answer about it being sent as text/html is the issue.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!