mod_rewrite and pretty urls

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

mod_rewrite and pretty urls

Post 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?
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

Try adding a <base href="webroot/"/> inside the <head>..

I wrestled with this problem for weeks before i remembered the <base> tag...
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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'>
User avatar
MrPotatoes
Forum Regular
Posts: 617
Joined: Wed May 24, 2006 6:42 am

Post 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
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

I don't mind using mod_rewrite... doesn't bother me really. I'll just deal with using absolute path
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post 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...
Post Reply