【问题标题】:My rewritten url redirecting but to a website without css or any other rule being applied我重写的 url 重定向但没有应用 css 或任何其他规则的网站
【发布时间】:2016-12-27 10:44:18
【问题描述】:

这是我原来的网址

http://havemybooks.com/blog_single?blog_no=39&blog=Ten%20quotes%20by%20national%20leader%20to%20make%20this%20independence%20day%20more%20speacial.

这是我重写的网址

http://havemybooks.com/blog_no/39/blog/Ten%20quotes%20by%20national%20leader%20to%20make%20this%20independence%20day%20more%20speacial.

这是我在 .htaccess 中使用的代码。我对 .htaccess 不太了解,所以我使用的是 htaccess 生成器工具。

RewriteEngine On
RewriteRule ^blog_no/([^/]*)/blog/([^/]*)$ /blog_single?blog_no=$1&blog=$2 [L]

这是我在检查网站元素时遇到的错误。

资源解释为样式表,但使用 MIME 类型 text/html 传输

【问题讨论】:

  • 你的问题是什么?
  • 我的代码有什么问题?这两个结果应该与我只是重写 url 相同。
  • 服务器是否启用了mod-rewrite?当您访问更漂亮的 URL 时,您会看到什么?
  • 如果您的 CSS/其他资产不起作用,请将 <base href="/"> 添加到您的 <head>
  • 是的,我启用了 mod 重写,这就是新链接有效的原因。 @hjpotter92

标签: apache .htaccess mod-rewrite friendly-url


【解决方案1】:

正如上面的Mike commented,您只需要从站点根目录加载静态内容。当前,您的所有 URL 都相对于您正在访问的页面呈现。

在您的<head> 页面中添加base tag,内容将根据需要加载。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-17
    • 2019-03-05
    • 1970-01-01
    • 2023-03-18
    • 2016-07-04
    • 1970-01-01
    • 2020-04-11
    相关资源
    最近更新 更多