The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Web Design
> CSS Help
|
paths to .js, .css, images lost when rewrite
Discuss paths to .js, .css, images lost when rewrite in the CSS Help forum on Dev Shed. paths to .js, .css, images lost when rewrite Cascading Style Sheets (CSS) forum discussing all levels of CSS, including CSS1, CSS2 and CSS Positioning. CSS provides a robust way of applying standardized design concepts to your web pages.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 31st, 2003, 07:10 AM
|
 |
Contributing User
|
|
Join Date: Dec 2002
Location: Barcelona
Posts: 133
Time spent in forums: < 1 sec
Reputation Power: 11
|
|
|
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
|

January 31st, 2003, 11:08 AM
|
|
Contributing User
|
|
Join Date: Oct 2000
Location: Back in the real world.
|
|
|
fix: donīt use mod_rewrite for that. use "DirectoryIndex" instead.
|

January 31st, 2003, 11:15 AM
|
 |
Contributing User
|
|
Join Date: Dec 2002
Location: Barcelona
Posts: 133
Time spent in forums: < 1 sec
Reputation Power: 11
|
|
|
Dont have access to httpd.conf, sorry, should've said that beforehand. Thanx for any input.
|

January 31st, 2003, 11:21 AM
|
|
Contributing User
|
|
Join Date: Oct 2000
Location: Back in the real world.
|
|
|
how are you doing the url rewriting then? in .htaccess?
try putting the DirectoryIndex directive there.
|

January 31st, 2003, 11:27 AM
|
 |
Contributing User
|
|
Join Date: Dec 2002
Location: Barcelona
Posts: 133
Time spent in forums: < 1 sec
Reputation Power: 11
|
|
|
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
|
|
Contributing User
|
|
Join Date: Oct 2000
Location: Back in the real world.
|
|
|
DirectoryIndex page.php
|

February 3rd, 2003, 04:45 AM
|
 |
Contributing User
|
|
Join Date: Dec 2002
Location: Barcelona
Posts: 133
Time spent in forums: < 1 sec
Reputation Power: 11
|
|
|
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
|
 |
11
|
|
Join Date: Jul 2001
Location: Lynn, MA
|
|
|
Then use absolute paths for your .js and .css files. Problem fixed.
|

February 3rd, 2003, 10:01 AM
|
 |
Contributing User
|
|
Join Date: Dec 2002
Location: Barcelona
Posts: 133
Time spent in forums: < 1 sec
Reputation Power: 11
|
|
|
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
|
 |
11
|
|
Join Date: Jul 2001
Location: Lynn, MA
|
|
|
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
|
 |
Contributing User
|
|
Join Date: Dec 2002
Location: Barcelona
Posts: 133
Time spent in forums: < 1 sec
Reputation Power: 11
|
|
|
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
|
 |
11
|
|
Join Date: Jul 2001
Location: Lynn, MA
|
|
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. . .
|

February 4th, 2003, 04:54 AM
|
 |
Contributing User
|
|
Join Date: Dec 2002
Location: Barcelona
Posts: 133
Time spent in forums: < 1 sec
Reputation Power: 11
|
|
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
|
|
Contributing User
|
|
Join Date: Jan 2001
Posts: 5
Time spent in forums: < 1 sec
Reputation 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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|