Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/39.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
Redirect index.php不会在php url参数中加载带有斜杠的css_Php_Css_.htaccess_Parameters - Fatal编程技术网

Redirect index.php不会在php url参数中加载带有斜杠的css

Redirect index.php不会在php url参数中加载带有斜杠的css,php,css,.htaccess,parameters,Php,Css,.htaccess,Parameters,我正在使用.htaccess从URL中删除index.php,并将其参数与/(斜杠)一起使用 例如,在: example.com/index.php?id=posts 之后: example.com/posts 我还使用.htaccess在参数中允许/(斜杠),例如:example.com/posts/mypost,其中posts/mypost是一个index.php参数 但我的问题是,当我使用/(斜杠)访问参数时,比如:example.com/posts/mypost,它会加载页面,但不会

我正在使用
.htaccess
从URL中删除
index.php
,并将其参数与
/
(斜杠)一起使用

例如,在:

example.com/index.php?id=posts
之后:

example.com/posts
我还使用
.htaccess
在参数中允许
/
(斜杠),例如:
example.com/posts/mypost
,其中
posts/mypost
是一个
index.php
参数

但我的问题是,当我使用
/
(斜杠)访问参数时,比如:
example.com/posts/mypost
,它会加载页面,但不会加载CSS,只有在使用
example.com/posts
中没有
//code>的情况下,它才会工作,或者只使用一个没有条的字符串!但是如果我删除
.htaccess
代码的这一部分:

RewriteCond %{THE_REQUEST} ^.*/index\.php

RewriteRule ^(.*)index.php$ /$1 [R=301,L]
带有斜杠的参数可以工作,但是使用
index.php?Id=
类似于:
example.com/index.php?Id=posts/mypost
。但这不是我想要的,我想要删除
index.php
,并使用他的参数和
/
斜杠

我的
.htaccess
完整代码:

#remove index.php
RewriteCond %{THE_REQUEST} ^.*/index\.php 
RewriteRule ^(.*)index.php$ /$1 [R=301,L] 

#use parameters without " ?id= "
RewriteEngine on
RewriteRule ^/?index.php$ - [L,NC]
RewriteRule ^([a-zA-Z0-9.]+)?$ index.php?id=$1 [QSA,L]

#allow " / " slash
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} !-d 
RewriteRule (.*) index.php?id=$1 [L,NS]
使用时:

<link rel="stylesheet" type="text/css" href="css/style.css">
无论您的文件夹有多深,浏览器都将始终指向文件的根目录

所以
example.com/posts
将查找
example.com/css/style.css


因此,
example.com/posts/more/和/more/和/more/和/more
在调用css文件时仍然会查找
example.com/css/style.css

当调用css文件时,您是在路径的开头有一个斜杠,还是使用的是绝对路径?@imvain2它没有斜杠,我认为它会转到另一个路径,因此它不会加载包含项,例如,当我输入mydomain.com/posts/mypost时,就好像posts是一个路径而不是“posts/mypost”参数如果调用CSS文件时没有前导斜杠,也没有将其作为绝对路径调用,CSS文件正在从地址栏中的路径加载为文件。我正在使用“检查浏览器中的网络流量”-浏览器正在请求的CSS文件的URL是什么(您可能会得到404)?仍然是一样的:/差不多一天我解决了问题,你帮了我该死的忙,谢谢你,兄弟:D,你能修改一下你的答案吗?这样我就可以接受它并投赞成票了?我不得不使用/mydomain/css/style.css
<link rel="stylesheet" type="text/css" href="/css/style.css">