Results 1 to 7 of 7

Thread: [RESOLVED] Pretty URL's

  1. #1

    Thread Starter
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Resolved [RESOLVED] Pretty URL's

    Hi,

    I'm giving pretty URL's a shot, but it's giving me headaches already.

    The setup is .htaccess with the following content:
    Code:
       RewriteCond %{SCRIPT_FILENAME} !-d
       RewriteCond %{SCRIPT_FILENAME} !-f
       RewriteRule ^([^\.]+)$ index.php?file=$1 [NC,L]
    And in PHP retrieving $_GET['file'].

    It kinda works, but the problem I'm facing is that when the path is deeper than 0 (e.g. /foo/bar) images and CSS don't work because the paths are incorrect (like img/foo.png).
    Now rather than hardcoding in the paths to the images and css, I was wondering if there is a way of tweaking the .htaccess a little bit more to fix that.
    Any other solutions would also be appreciated.

    Thanks
    Delete it. They just clutter threads anyway.

  2. #2
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: Pretty URL's

    Why not use absolute paths to images and CSS?

    http://webdesign.about.com/od/beginn.../aa040502a.htm

    For example:

    Instead of ../../css/screen.css
    Use /css/screen.css

    I don't think this is a .htaccess problem, it's a problem with your paths to your resources.

  3. #3
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Pretty URL's

    yeah, I'd do what ILMV suggested. either store a constant that defines an absolute path (including your domain), or use the types of absolute paths that ILMV described.

    I'm sure there's something you might be able to do that captures anything with a "css/" or "img/" directory and then rewrites to the correct directory, but it's a little unnecessary when you can solve the problem so easily by prepending a slash onto your URLs.

  4. #4
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: Pretty URL's

    Many years ago (before I knew about absolute URLs) I used a crazy complicated bit of PHP to calculate how many ../'s I needed for my resource links.

    Not only are absolute URLs a bajillion times more effective but it increases portability, say you want to copy your design to a sub domain, if your resources directly refer to the domain they will be useless under a different address.

    In my current job we are being ultra cautious to make our project as portable as possible, because we don't know if one of our partner organisations are going to want this in a sub domain of their corporate URL, or if their going to want to use Oracle instead of PostgreSQL.

    Think portability!

  5. #5

    Thread Starter
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: Pretty URL's

    Maybe I should've added that I'm building a little cms with templates and all.

    Portability was pretty much the issue.
    Imagine I'd have a complete site in a subdirectory which I do in localhost;
    http://localhost/foo/bar.php
    For the template, hardcoding in the URL would be a no-go as that would vary on systems and pretty much destroy the portability.

    But I've worked out that the base path should be a general setting so I can glue that in front of the url's that would fail otherwise.
    (I'm having difficulties building this sentence, hope you understand it )

    Anywany, thanks for the input!
    Delete it. They just clutter threads anyway.

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [RESOLVED] Pretty URL's

    Yes, the typical solution is to have a base URI for your product, which is itself an absolute URI.

    There's also a HTML base tag, which has its own set of pitfalls.

  7. #7

    Thread Starter
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: [RESOLVED] Pretty URL's

    Although I don't give a sh about IE6 users, I think it should be done server-side.
    But nice tip, didn't know that one.
    Delete it. They just clutter threads anyway.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width