January 31st, 2003, 07:10 AM
paths to .js, .css, images lost when rewrite
I managed to run the following rewrite:
that basically returns sub.domain.com/version/page.php when asked for sub.domain.com/version/page/
RewriteRule ^(.*).*/(.*)/ /$1.php
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
January 31st, 2003, 11:08 AM
fix: donīt use mod_rewrite for that. use "DirectoryIndex" instead.
January 31st, 2003, 11:15 AM
Dont have access to httpd.conf, sorry, should've said that beforehand. Thanx for any input.
January 31st, 2003, 11:21 AM
how are you doing the url rewriting then? in .htaccess?
try putting the DirectoryIndex directive there.
January 31st, 2003, 11:27 AM
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?
January 31st, 2003, 11:32 AM
February 3rd, 2003, 04:45 AM
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.
February 3rd, 2003, 09:55 AM
Then use absolute paths for your .js and .css files. Problem fixed.
February 3rd, 2003, 10:01 AM
No, I dont want to, problem not fixed. Isnt there any fix for that? I cannt believe it. Thanx anyway.
February 3rd, 2003, 10:31 AM
What's wrong with absolute paths? You don't have to put in a domain name. . .but you probably knew that.
February 3rd, 2003, 10:38 AM
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.
February 3rd, 2003, 11:32 AM
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:
then, no matter where they are referenced from, they work.
<LINK REL="stylesheet" TYPE="text/css" HREF="/css-global/global.css">
<LINK REL="stylesheet" TYPE="text/css" HREF="/css-lib/diversity.css">
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. . .
February 4th, 2003, 04:54 AM
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 05:01 AM.
February 10th, 2003, 04:28 AM
>> 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.