Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.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
Css包括在PHP中实现modrewrite时不工作_Php_Html_Css - Fatal编程技术网

Css包括在PHP中实现modrewrite时不工作

Css包括在PHP中实现modrewrite时不工作,php,html,css,Php,Html,Css,我正在做wamp。 我的站点的链接是:localhost/tshirtshop/ 在重写之前,它是:localhost/tshirtshop/index.php?product=12 重写后为:localhost/product-title-p12 问题: 一切正常。但问题在于Css文件。 此文件不包括。。当我看到源代码(Ctrl+U)时,路径如下: localhost/tshirtshop/product-title-p12/styles/tshirtshop.css 我的尝试: 我试过这个

我正在做wamp。 我的站点的链接是:localhost/tshirtshop/

在重写之前,它是:localhost/tshirtshop/index.php?product=12

重写后为:localhost/product-title-p12

问题: 一切正常。但问题在于Css文件。

此文件不包括。。当我看到源代码(Ctrl+U)时,路径如下:

localhost/tshirtshop/product-title-p12/styles/tshirtshop.css

我的尝试:

我试过这个

<style>
    <?php include 'styles/tshirtshop.css';
   </style>


CSS不像典型的服务器脚本那样包含在PHP中,它通过客户端web浏览器呈现的HTML链接

因此,与此相反:

<style>
    <?php include 'styles/tshirtshop.css';
</style>


是的,您应该避免使用css和js的相对路径。如果您在Apache的mod_rewrite中使用seo URL,那么只有完整路径才能为您提供帮助。因此:

<link rel="stylesheet" type="text/css" href="theme.css">
在以下位置搜索css文件:

http://www.mypage.com/seo-url/theme.css
这是不存在的。而这:

http://www.mypage.com/theme.css
这就是你想要的。因此,请从一开始就使用:

<link rel="stylesheet" type="text/css" href="http://www.mypage.com/theme.css">


你就完了。与js相同。

使用绝对路径,如

<link rel="stylesheet" type="text/css" href="http://localhost/tshirtshop/styles/tshirtshop.css" />

如果不查看您的
.htaccess
文件(如果您可以包括,我们可以帮助您进一步调试),我就无法准确地说出问题所在。 但我有理由猜测它只是有一个
重写规则

在重写规则之前,您应该包括以下内容:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Your rewrite rule here...
<base href="http://www.example.com/">
还有其他选择。您可以在HTML标记中指定

看起来是这样的:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Your rewrite rule here...
<base href="http://www.example.com/">


这将允许您像当前一样使用相对路径。您的另一个选择是按照其他答案中的说明执行,但是谁想检查所有代码并重新编写所有内容?

请显示css的链接标记?使用此路径它将变成:localhost/styles/tshirtshop.css。甚至不适用于主页。绝对URL(以斜线开头)开始在文档根目录中搜索。当您访问“localhost/”时,无论服务器在查看哪个文件夹,请将tshirtshop.css放在相对于该位置的“styles/tshirtshop.css”中,它应该可以正常工作。谢谢。我使用了这个它正在工作,但当用户通过example.com或www.example.com访问站点时会出现问题吗?您应该使用默认格式,如
http://www.mypage.com
获取完整的URL。如果您的服务器设置为正确重定向
http://mypage.com
http://www.mypage.com
那你就没事了。谢谢。我用过这个它正在工作,但当用户通过example.com或www.example.com或htt p://example.com访问站点时会出现问题吗?请在config中设置css路径值file@Abrar是的,会的。您必须将所有这些
localhost/
更改为
example.com/
,或者创建一个保存其值的配置文件。