#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Barcelona
    Posts
    133
    Rep Power
    13

    paths to .js, .css, images lost when rewrite


    I managed to run the following rewrite:
    PHP Code:
    RewriteEngine on
    RewriteRule 
    ^(.*).*/(.*)/ /$1.php 
    that basically returns sub.domain.com/version/page.php when asked for sub.domain.com/version/page/
    You see it's a simplified case. The problem here is paths to .js, .css and images are lost and I dont see them unless I declare them absolute (sub.domain.com/fullpath...) which obviously sucks. Any fix? Thanx
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    191
    fix: donīt use mod_rewrite for that. use "DirectoryIndex" instead.
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Barcelona
    Posts
    133
    Rep Power
    13
    Dont have access to httpd.conf, sorry, should've said that beforehand. Thanx for any input.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    191
    how are you doing the url rewriting then? in .htaccess?
    try putting the DirectoryIndex directive there.
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Barcelona
    Posts
    133
    Rep Power
    13
    yes, using .htaccess. thanx, i'll have a look around here, if i dont find similar threads i'll ask again. Or can u post a simple example of how to do that using DirectoryIndex directive in .htaccess?
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    191
    DirectoryIndex page.php
  12. #7
  13. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Barcelona
    Posts
    133
    Rep Power
    13
    Sorry, i dont think you've read my problem, DirectoryIndex directive does other things. Thanx anyway.

    I'll explain the problem again:

    I have a folder we'll call 'version'. Under that folder there are the main php pages that become the sections of the site. I want those pages become folder status using .htaccess, but when doing so, references to relative paths (images, css, js, etc) are lost.
  14. #8
  15. 11
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Jul 2001
    Location
    Lynn, MA
    Posts
    4,635
    Rep Power
    83
    Then use absolute paths for your .js and .css files. Problem fixed.
  16. #9
  17. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Barcelona
    Posts
    133
    Rep Power
    13
    No, I dont want to, problem not fixed. Isnt there any fix for that? I cannt believe it. Thanx anyway.
  18. #10
  19. 11
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Jul 2001
    Location
    Lynn, MA
    Posts
    4,635
    Rep Power
    83
    What's wrong with absolute paths? You don't have to put in a domain name. . .but you probably knew that.
  20. #11
  21. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Barcelona
    Posts
    133
    Rep Power
    13
    I wouldnt like to HAVE to change all the links in a site, you know. I'm all ears, if you want to enlighten me with an example i'll appreciate a lot.
  22. #12
  23. 11
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Jul 2001
    Location
    Lynn, MA
    Posts
    4,635
    Rep Power
    83
    Hindsight is 20-20 they say. You should've gone with absolute paths from the start.

    What I do for my sites is define a "js-lib" and "css-lib" directory directly up from the root that I put all my shared files in, then whenever I have to reference one of them I just put them in as absolute links:

    Code:
    <LINK REL="stylesheet" TYPE="text/css" HREF="/css-global/global.css"> 
    <LINK REL="stylesheet" TYPE="text/css" HREF="/css-lib/diversity.css"> 
    <script language="JavaScript" src="/js-global/global.js" type="text/javascript"></script>
    then, no matter where they are referenced from, they work.

    The problems you're having are the exact reason NOT to use relative paths.

    You could write a mod_perl post processing handler to fix the links, but it'd probably be better just to mass-update your links. There are a number of perl one-liners to do this. . .
  24. #13
  25. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Barcelona
    Posts
    133
    Rep Power
    13
    cannt use that short way of absolute paths cause my subdomain can be accessed to from subdomain.domain.com or domain.com/subdomain. Obviously I dont want to change all my image references neither.

    I dont want to use perl cause I'm already using php and cannt mix both on the same page.

    I made a very simple test page with simple css/js/jpg associated files (all less than 3kb): http://meddle.dzygn.com/tests/htaccess/test.html

    The main question is:
    How can I make the page accessible through a non-existing http://meddle.dzygn.com/tests/htaccess/test/ (see the folder status)? And I'd need the associated files not corrupted by the rewrite change, so still accessible.

    Thanx a lot.
    Last edited by meddle; February 4th, 2003 at 06:01 AM.
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2001
    Posts
    4
    Rep Power
    0
    >> The problem here is paths to .js, .css and images are lost

    Then fix your useless RewriteRule (because of using wildcard all over which basically matches everything more than you want it to really match) by adding a RewriteCond and another RewriteRule. When you are stuck just start here and pay attention to the keyword: Passthru or PT within RewriteRule.

IMN logo majestic logo threadwatch logo seochat tools logo