【问题标题】:ModRewrite and the urlModRewrite 和 url
【发布时间】:2012-02-15 04:35:27
【问题描述】:

我有类似的东西:

.htaccess:

RewriteRule ^news/?(\d+)/?$ /?pg=news&id=$1 [NC]

header.php:

<link rel="stylesheet" href="../theme/style.css" media="all" >

问题如下:当我转到 www.domain.com/news/241 时,我收到 style.css 的错误“404 Not Found”文件。

我将../theme/style.css 替换为&lt;?=HOST;?&gt;/theme/style.css,其中HOST 是域名。如何做得更好?

【问题讨论】:

    标签: php html .htaccess url


    【解决方案1】:

    只需对所有链接/资产(js、css、图像等)使用绝对路径:

    /theme/style.css
    

    【讨论】:

      【解决方案2】:

      您需要在重写规则之前包含一个重写规则,排除您的内容目录:

      RewriteRule ^(images¦javascript¦theme) - [L]
      

      上面的规则告诉mod_rewrite排除匹配的目录

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-07
        • 1970-01-01
        • 2012-07-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多