【问题标题】:Sef URL CSS ProblemsSef URL CSS 问题
【发布时间】:2014-05-18 14:23:37
【问题描述】:

我尝试像这样创建搜索引擎友好的 URL;:

RewriteRule ^m/([0-9]+)$ my.php?id=$1

但是,它获取的页面没有 CSS。

如果我这样写:

RewriteRule ^([0-9]+)$ my.php?id=$1

它可以毫无问题地使用 CSS 获取页面。

我该如何解决?

【问题讨论】:

  • 我的回答不正确吗?

标签: php .htaccess url


【解决方案1】:

当你像这样编写 CSS 引用时:

<link rel="stylesheet" type="text/css" href="style.css">

这是一个相对 URL。在http://example.com/ 上,它指向http://example.com/style.css,但在http://example.com/my/1 上,它指向http://example.com/my/style.css,它不存在。

使用绝对 URL 可以解决这个问题:

<link rel="stylesheet" type="text/css" href="/style.css">

【讨论】:

    【解决方案2】:

    这可以通过在每个页面的head标签中添加base属性来解决:

    <base href="http://www.example.com/" />
    

    或在 css 前添加 /

    <link rel="stylesheet" type="text/css" href="/stylesheet.css">
    

    发生的情况是,当您重定向页面时,它也在寻找 my/css 中的 CSS,而不是 css,添加上述内容将解决此问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-16
      • 1970-01-01
      • 1970-01-01
      • 2010-12-06
      相关资源
      最近更新 更多