Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 清除URL->;URL';只有1个参数的s可以工作,但超过1个参数的CSS文件将不包括在内_.htaccess_Mod Rewrite_Url Routing_Clean Urls - Fatal编程技术网

.htaccess 清除URL->;URL';只有1个参数的s可以工作,但超过1个参数的CSS文件将不包括在内

.htaccess 清除URL->;URL';只有1个参数的s可以工作,但超过1个参数的CSS文件将不包括在内,.htaccess,mod-rewrite,url-routing,clean-urls,.htaccess,Mod Rewrite,Url Routing,Clean Urls,我在我的项目中使用干净的URL。为了简单起见,我简化了代码 我的.htaccess: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php [L] My index.php: <?php require_once "/login.php"; ?> 但是如

我在我的项目中使用干净的URL。为了简单起见,我简化了代码

我的.htaccess:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
My index.php:

<?php
    
    require_once "/login.php";
        
?>
但是如果我请求一个带有2个参数的URL,比如:

http://localhost/test/bla/bla 
然后显示登录页面,但没有所有css样式(未包含css文件…)


但是为什么呢?

之所以会发生这种情况,是因为您将css包含在一个相对url中,所以实际上您正在尝试加载

http://server.com/test/bla/bootstrap/css/bootstrap.min.css
而不是

http://server.com/test/bootstrap/css/bootstrap.min.css
这不是一个干净的URL问题。快速解决方法:

<link href="/test/bootstrap/css/bootstrap.min.css" rel="stylesheet">


毕竟,对于给定的项目,资产目录不会经常更改。

首先,如果您的htaccess位于
test
文件夹中,它应该是这样的

RewriteEngine On
RewriteBase /test/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
然后,您还必须为css和js链接添加重写基(对于包含许多虚拟目录的绝对路径)

<link href="/test/bootstrap/css/bootstrap.min.css" rel="stylesheet">

但您可以在html页面中简单地使用它,并保持css/js链接不变

<base href="/test/" />

坦克太多了!(基本标签不是必需的)。不客气。正如我所说,这是没有必要的,它只会避免您在每个css/js链接中重复
/test/
<link href="/test/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<base href="/test/" />