【发布时间】:2018-06-04 19:06:24
【问题描述】:
我正在使用 apache mod_rewrite、htaccess。
我找到了一种方法来实现图像/css/js 文件访问,而无需在 html/pages 中写入完整的 url 路径,来自某个站点,(我忘记了该站点)。
所以,我用 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
所以,所有的js,css访问。
但现在我添加了另一个规则
RewriteRule script/js/(.+)?$ script/$1 [NC,L] # it should take js from script/js
它不起作用。
我知道现在目录结构是两级的,即 script/js/ 所以它无法解析“js”文件夹中的文件。但不知道如何处理。
我尝试了很多,使用不同的模式,但失败了。
再一次,我的问题是访问:
1) script/js/anyfile.js
2) script/css/anycssfile.css
3) script/blue_theme/Anyimagesfile.jpg
4) script/css/jquery/images/anyimages.jpg
目录结构如下:
-脚本 -js -css -jquery -图片 -blue_theme此外,获取这些资源的路径由 .httaccess 评估:
http://localhost/site/Place-an-ad/Cars/Mazda/mazda-y/mazda-y-2/script/js/anyjsfile.js
【问题讨论】:
-
实际上,首先我将站点 url 分配给一个变量,然后将其粘贴到每个相对 url。像 localhost/site/";?> 并粘贴为 但它在dreamweaver 中产生了设计问题,因为在这种情况下,dreamweaver 无法访问css。感谢您的回复,但我希望相对网址正常。
标签: apache mod-rewrite url-rewriting