请求“ .example.php /”之类的.php时,css无法工作,但显示内容

时间:2018-10-28 15:29:30

标签: php html css .htaccess url

im用php开发脚本,我将每个部分都分离为.php文件,以便将它们包含在include()php函数中。

所以我分开

  1. header.php
  2. footer.php
  3. 等。

使用include()在每个文件夹中一切正常,例如,如果要在浏览器中查看文件,则为

http://localhost/yourfile.php很好!

http://localhost/yourfile.php/不好!

当您添加(/)时,它将显示yourfile.php的内容,但没有CSS!

我尝试添加具有值

.htaccess

 if let iCloudDocumentsURL = FileManager.default.url(forUbiquityContainerIdentifier: nil) {
        let finalUrl = iCloudDocumentsURL.appendingPathComponent("Document")
        if !FileManager.default.fileExists(atPath: finalUrl.path) {
            try? FileManager.default.createDirectory(at: finalUrl, withIntermediateDirectories: true, attributes: nil)
        }
    }

和标头值

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /snapchat/index.php [L]
</IfModule>

2 个答案:

答案 0 :(得分:0)

那是因为您的css链接是相对的,例如assest/css/styles.css,因此浏览器尝试从http://localhost/yourfile.php/assest/css/styles.css下载样式。

如果您将css的传递更改为此/assest/css/styles.css,则浏览器将从http://localhost/assest/css/styles.css加载样式(请考虑路径开头的/

答案 1 :(得分:0)

由于您正在重写网址,因此需要在样式表之前添加斜杠

import cgi
import os

def f_get_ipaddress():
    try:
        ipaddress = cgi.escape(os.environ["REMOTE_ADDR"])
    except:
        ipaddress = "127.0.0.1"

    return ipaddress

print "Content-type: text/html"
print ""

ipaddress = f_get_ipaddress()

print ipaddress

那将解决您的问题!