1

I am using apache mod_rewrite, htaccess.

I find a way to achieve images/css/js file access without writing full url path in html/pages, from some site,(i forgot the site).

So, I write in htaccess:

RewriteRule images/(.+)?$ images/$1 [NC,L]     # it take images from images folder
RewriteRule js/(.+)?$ js/$1 [NC,L]             # it take js files from js folder
RewriteRule topnav/(.+)?$ topnav/$1 [NC,L]     # it take js/css from topnav folder
RewriteRule common-style.css common-style.css # it take css from root folder
RewriteRule jquery.js jquery.js    # it take jquery from root folder

so, all js,css access.

but now i added another rule

RewriteRule script/js/(.+)?$ script/$1 [NC,L] # it should take js from script/js

it doesnot work.

i understand that now directory structure is two level i.e. script/js/ so it could not resolve file in "js" folder. but not know how to handle this.

I tried a lot, using different pattern, but faild.

Once again, My question is to access :

1) script/js/anyfile.js
2) script/css/anycssfile.css
3) script/blue_theme/Anyimagesfile.jpg
4) script/css/jquery/images/anyimages.jpg

Directory structure is as follow:

-script
        -js
        -css
           -jquery
                   -images       
        -blue_theme

Also, the path to fetch these resources is evaluated as by .httaccess:

http://localhost/site/Place-an-ad/Cars/Mazda/mazda-y/mazda-y-2/script/js/anyjsfile.js

but it is actualy at. http://localhost/site/script/js/anyjsfile.js

1
  • actually, first i assign site url to a variable, and paste it with every relative url. like <?php $baseurl="localhost/site/";?> and paste as <link rel="alternate stylesheet" type="text/css" href="<?php echo $baseurl;?>script/blue_theme/style-blue.css" title="style_purple" media="screen" /> <script type="text/javascript" src="<?php echo $baseurl;?>script/js/jquery-ui-1.8.2.js"></script> but it create design issue in dreamweaver, because css is inaccessible by dreamweaver in this case. thanks for ur response, but i want relative urls as normal. Commented Feb 8, 2011 at 11:01

1 Answer 1

3

Your patterns do only match paths that either end with the given pattern (pattern ends with $) or just contains the given pattern (no $). And the problem is that the pattern js/(.+)?$ will also match script/js/ and so on.

Make your pattern more specific by providing both the start and the end of the path by using ^ and $:

RewriteRule ^images/(.+)?$ images/$1 [NC,L]
RewriteRule ^js/(.+)?$ js/$1 [NC,L]
RewriteRule ^topnav/(.+)?$ topnav/$1 [NC,L]
RewriteRule ^common-style\.css$ common-style.css
RewriteRule ^jquery\.js$ jquery.js

And then do the same with your new rule:

RewriteRule ^script/js/(.+)?$ script/$1 [NC,L]
Sign up to request clarification or add additional context in comments.

1 Comment

thank you, you identify the real issue. js/ that comes in two rules and results in conflict.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.