重写.htaccess中的静态文件
我在子文件夹 http://example.com/some/other/sub/folder/
中有应用程序。 和 .htaccess 文件:
RewriteEngine on
RewriteBase /some/other/sub/folder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?p=$1 [QSA,L]
模板文件包含图像、js 和 css 文件的绝对 URL:/images/header.png
、/js/common.js
等。
我的问题是具有绝对路径的静态文件不可访问。
谢谢。
I have application in subfolder http://example.com/some/other/sub/folder/
.
And .htaccess file:
RewriteEngine on
RewriteBase /some/other/sub/folder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?p=$1 [QSA,L]
Template files contain absolute URL to the images, js and css files: /images/header.png
, /js/common.js
etc.
My problem is that static files with absolute paths is not accessible.
Thx.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
原因是,通过绝对 URL 路径
/images/header.png
的引用,您实际上引用了/images/header.png
而不是/some/other /sub/folder/images/header.png
。使用与
/some/other/sub/folder/
一起使用的相对 URL 路径作为基本路径。或者使用绝对 URL 路径,例如/some/other/sub/folder/images/header.png
,它们独立于实际的基本路径。The reason is that with a reference of an absolute URL path
/images/header.png
you actually reference/images/header.png
and not/some/other/sub/folder/images/header.png
.Either use relative URL paths that work with
/some/other/sub/folder/
as the base path. Or use absolute URL paths like/some/other/sub/folder/images/header.png
that then are independent to the actual base path.