SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Friendly urls and images in css

    Hey.
    I have been trying to make all my urls search engine friendly by using mod_rewrite to route all urls to index.php/url.

    This is working perfectly, but problems occur if I use url like /user/edit/someuser. All my image paths in css file won't work anymore. I have just a regular css, something like background-image: url(images/background.gif).

    The css works when viewing index.php or /, but immediately if url changes to /user/ it won't work anymore.

    Is there some clever way to solve this problem? Any suggestions much appreciated!

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Use paths relative to the root of the site in your CSS. Adding a forward slash at the beginning will do it.

    Code:
    background-image: url(/images/background.gif)

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was thinking about that, but unfortunately I develop sites on my own computer and when I upload the site to the actual web server, those paths won't match anymore.

    This approach would require a lot of search&replace before uploading the css files. Is there any other methods or should I just search&replace (this seems a little bit clumsy).

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by js_11 View Post
    I was thinking about that, but unfortunately I develop sites on my own computer and when I upload the site to the actual web server, those paths won't match anymore.
    If you develop locally with a different virtual host for each site, then it'll be identical on your computer and on the web server.

    E.g. http://domain.com live, http://domain local

  5. #5
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh yeah thats true. I think I'll have to re-design my local develoment environment, for now it has been like localhost/stuff/site1 or localhost/site2 etc.

  6. #6
    SitePoint Guru bronze trophy TomB's Avatar
    Join Date
    Oct 2005
    Location
    Milton Keynes, UK
    Posts
    988
    Mentioned
    9 Post(s)
    Tagged
    2 Thread(s)
    The easiest method is to specify a html <base> tag.

  7. #7
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by TomB View Post
    The easiest method is to specify a html <base> tag.
    Wonderful! This did the trick and everything seems to work!
    At least for now, I'll go with this simple but effective <base> tag.


Bookmarks

Posting Permissions

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