CSS的mod_rewrite包含问题 [英] Mod_rewrite inclusion problem with css

查看:104
本文介绍了CSS的mod_rewrite包含问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是mod_rewrite的新手.

I new to mod_rewrite.

我有此页面 profiles.php?page = XXX

我试图将其移至更友好的网址/cars/XXX/

i tried to move it to more friendly url /cars/XXX/

RewriteEngine on
RewriteRule ^cars/([^/]+)/?$ profiles.php?page=$1 [L]

问题是当我包含样式

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

它不起作用,

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

可以正常工作,但不能与profile.php?carname = XXX一起使用

works fine, but wont work with profile.php?carname=XXX

为什么会这样?我该如何解决

why is that happening ? how can i fix it

注意:

我有一个小脚本,可以通过计算/

I have a small script that determine the base address of website by counting number of /

global $base_addr;
$s=substr_count($_SERVER['SCRIPT_NAME'],"/",2)-1;
$base_addr=".";
if($s > 0)$base_addr.=str_repeat("/..",$s);
require_once($base_addr.'class/xxx.php');
echo "<link href='$Base_addr/css/style.css' rel='stylesheet' type='text/css' />";

在此代码中require_once可以完美地工作,只有html hrefs是我的问题,对此没有任何解决办法

In this code require_once will works perfectly, only html hrefs is my problem any fix for that

推荐答案

我认为这种方法效果更好.

I think that this works better.

<base href="/" />  

特别是因为您可以定义网站的基本根目录,所以子目录中的css或jquery之类的资产都不会丢失.

Especially since you can define the base root of your site, then none of the assets like css or jquery in sub directories get lost.

<base href="www.url.org/" /> 
<base href="www.url.org/directory/" /> 

这篇关于CSS的mod_rewrite包含问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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