【问题标题】:Mod_rewrite - CSS, JS and Images not workingMod_rewrite - CSS、JS 和图像不起作用
【发布时间】:2015-09-28 22:25:55
【问题描述】:

这是我第一次在这里提问。
我对 mod_rewrite 有疑问。

我有以下文件系统结构:

site_new/stylesheets/layout.css  
site_new/javascript/somescript.js  
site_new/hallendetails.php  
site_new/etc...

现在我尝试通过 mod_rewrite 将我的 php 页面重定向到 html 文件。
它工作正常,我的 .htaccess 看起来像这样:

RewriteEngine on  
RewriteBase /site_new/  
RewriteRule ^(.*)/(.*).html$ hallendetails.php?id=$1&halle=$2 [L]  

原始网址为:

localhost/site_new/hallendetails.php?id=01&halle=Heimspielhalle_Gaissacher_Strasse

“新”网址是:

localhost/site_new/01/Heimspielhalle_Gaissacher_Strasse.html

现在我所有的 CSS、JS 和图像文件都损坏了。
它们是这样包含的:
type="text/css" href="stylesheets/layout.css"

但是在重定向之后他们会被搜索到

/site_new/01/stylesheets/layout.css

我想我需要一个 RewriteCond,但我不知道怎么写。试了很多方法,还是不明白。

请帮忙!

【问题讨论】:

  • 输入type="text/css" href="/stylesheets/layout.css" 试试看(见路径开头的附加/)。
  • 感谢您的提示,但它使用的是 localhost/stylesheets/layout.css 链接,而不是 localhost/site_new/stylesheets/layout.css。所以我可以添加../,但每次上传到网络服务器时都必须重新修改它。

标签: css apache .htaccess mod-rewrite url-rewriting


【解决方案1】:

使用mod_rewrite时尝试css,images,js的绝对路径

【讨论】:

    猜你喜欢
    • 2012-08-04
    • 2016-03-28
    • 2012-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-21
    • 1970-01-01
    • 2017-11-10
    相关资源
    最近更新 更多