开发者

htaccess mod_rewrite css/js/images access issue

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
R开发者_运维问答ewriteRule 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


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]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜