简体   繁体   English

Sef URL CSS 问题

[英]Sef URL CSS Problems

I try to create Search Engine Friendly URLS like this;:我尝试像这样创建搜索引擎友好的 URL;:

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

However, it gets the page without CSS.但是,它获取没有 CSS 的页面。

If I write like this:如果我这样写:

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

it gets the page with CSS without any problem.它可以毫无问题地获取带有 CSS 的页面。

How can I solve it?我该如何解决?

This can be fixed by adding a base attribute to the head tag of each page:这可以通过向每个页面的 head 标记添加一个base属性来解决:

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

or add / before the css.或者在css之前添加/

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

What was happening was that when you were redirecting the page, it was also looking for the css in my/css instead of css adding the above will fix that.发生的事情是,当您重定向页面时,它还在my/css查找my/css而不是css添加上述内容将解决该问题。

When you write CSS references like this:当您像这样编写 CSS 引用时:

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

it's a relative URL.它是一个相对 URL。 On http://example.com/ , that points to http://example.com/style.css , but on http://example.com/my/1 it points to http://example.com/my/style.css , which doesn't exist.http://example.com/ ,它指向http://example.com/style.css ,但在http://example.com/my/1它指向http://example.com/my/style.css ,它不存在。

Using an absolute URL fixes this:使用绝对 URL 可以解决这个问题:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM