使用htaccess和css处理404错误 [英] 404 error handling with htaccess and css

查看:134
本文介绍了使用htaccess和css处理404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我的404错误处理有问题。



我添加到htaccess中:


ErrorDocument 404 /404.php


所以如果输入如下内容:


www.domain.com/abc


一切正常,我的php页面。问题将出现在输入如下内容时:


www.domain.com/abc/




表示向url添加一个斜杠404错误页面出现,但不加载css文件?



如果存在是一个谁可以告诉我什么是错在这里,我真的很感激。

非常感谢。

解决方案

由于404页面将从任何URL显示,因此您需要为CSS文件,图像,JavaScript文件等任何外部页面资产使用绝对路径。



因此,任何相对路径...

 < link type =text / css rel =stylesheetmedia =screenhref =site.css/> 

将需要更改为绝对路径...

 < link type =text / css =stylesheetmedia =screenhref =/ site.css/> 


hello i have a problem with my 404 error handling.

i added to htaccess:

ErrorDocument 404 /404.php

so in case of typing something like:

www.domain.com/abc

everything works fine with my php page. the problem will be when typing something like:

www.domain.com/abc/

means adding a slash to the url the 404 error page appears but doesn*t load the css file?

if there is someone who could tell me whats going wrong over here, i really would appreciate.

thanks alot.

解决方案

Since the 404 page will be displayed from any URL, you will need to use absolute paths for any external page assets like CSS files, images, JavaScript files, etc.

So any relative paths...

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

will need to be changed to absolute paths...

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

这篇关于使用htaccess和css处理404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆