Page 1 of 1

mod_rewrite and pretty urls

Posted: Thu Sep 28, 2006 2:07 pm
by Luke
I am trying to build an application with prettier urls (no query strings). So far I've had no problems because I've always just used a full url to my stylesheets. Well... I would like to be able to use a relative path and not have to define a wwwroot variable in my config.
So my html would look like this:

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title>Directory</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <link rel='stylesheet' href='styles/style.css' type='text/css'> </head>
 <body> 
  <!-- Body //--> 
 </body>
</html>
My directory structure is like this...

Code: Select all

-root
  -application
    +controller
    +model
    +view
  +library
  -public
    +images
    +scripts
    -styles
       style.css
  .htaccess
  index.php
and my .htaccess file looks like this:

Code: Select all

<IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php
</IfModule>
but the link tag to my stylesheet just isn't working. It doesn't load my stylesheet. Anybody know what I'm doing wrong?

Posted: Thu Sep 28, 2006 3:23 pm
by nickvd
Try adding a <base href="webroot/"/> inside the <head>..

I wrestled with this problem for weeks before i remembered the <base> tag...

Posted: Thu Sep 28, 2006 3:28 pm
by Luke
well I thought about the base tag as well, but that is sort of just going around the problem. I thought there was a way to do what I want without the base tag.

EDIT: I remember reading somewhere on this forum that when using pretty urls, you have to use absolute paths anyway, so this is what I'm doing until I can find something better (if it even exists)

Code: Select all

<link rel='stylesheet' href='/chamberdirectory/public/styles/main.web.css' type='text/css'>

Posted: Thu Sep 28, 2006 3:34 pm
by MrPotatoes
if you don't mind the index.php in there i've done it w/o mod_rewrite. it was the biggest conversion that i've had to do to my system to date. didn't kill me but dammit man, it wasn't terribly fun lmao

Posted: Thu Sep 28, 2006 3:39 pm
by Luke
I don't mind using mod_rewrite... doesn't bother me really. I'll just deal with using absolute path

Posted: Thu Sep 28, 2006 4:07 pm
by nickvd
My older solution was to rewrite everything EXCEPT .css .jpg .gif .png .js etc. etc etc... that way the requests still go through, but you can still access the images/css/js via relative urls...

I also don't see the base tag as being a work-around, as it is part of the language for purposes such as this...