【问题标题】:Apache PHP relative path not recognisedApache PHP 相对路径无法识别
【发布时间】:2016-03-25 22:14:58
【问题描述】:

我一直在安装 Ushahidi 平台客户端。由于 mod rewrite,我得到了 API 的工作。现在我正在设置平台客户端,但我没有成功。

这是我的 html 文档设置:

html
     index.html
     about.html
     平台客户端          服务器
         www
             .htaccess
             index.html

这是我的平台客户端中的 .htaccess:

RewriteEngine on

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ /index.html  [PT,L]

这里是平台客户端/服务器/www/index.html:

<!doctype html>
<html lang="en" ng-strict-di>
<head ng-controller="PageMetadata">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="/fonts/Lato/css/fonts.css" rel="stylesheet" type="text/css">
    <!-- @todo minify CSS -->
    <link rel="stylesheet" href="/css/style.css" ng-href="{{rtlEnabled ? '/css/rtl-style.css' : '/css/style.css'}}">
    <link rel="stylesheet" href="/css/vendor.css">
    <script src="/config.js"></script>

    <title ng-bind-template="{{pageTitle}} {{siteTitle}}"></title>
    <meta name="description" content="{{pageDescription}}">
    <meta name="keywords" content="{{pageKeywords}}">
    <meta name="robots" content="{{pageRobots}}">
    <base href="/">
</head>

<body ng-class="{ rtl : rtlEnabled }" class="has-dynamic-header" canvas>
    <div id="bootstrap-loading">
        <header class="header header-full overlay" role="banner">
            <div class="container">
                <div class="color-overlay">
                    <div class="parallax">
                        <h1 class="beta"><i class="fa fa-refresh fa-4 fa-spin"></i></h1>
                    </div>
                </div>
            </div>
        </header>
    </div>

等等……

当我运行该站点时,我得到的是错误显示,而不是正确的显示。当我还检查元素时,我看到 /css/style.css 指向我的根目录,即域。

 www.example.com/css/style.css

应该是:

www.example.com/platform-client/server/www/css/style.css

更新:这是我的 httpd.conf:

NameVirtualHost *:80

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ServerName example.com
ServerAlias www.example.com
</VirtualHost>

<VirtualHost *:80>
ServerAdmin webmaster@example.com
DocumentRoot /var/www/html/platform-client/server/www
ServerName example.com/platform-client/server/www
<Directory "/var/www/html/platform-client/server/www">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
</VirtualHost>

我的设置有问题吗?我真的需要你的帮助,因为我已经修复了将近一个星期,但没有成功。我很乐意为您提供任何帮助。谢谢!

【问题讨论】:

  • 假设您显示的 index.html 是 /platform-client/www/ 文件夹中的那个,您可以尝试在链接中删除前导斜杠:
  • @Gralgrathor 感谢您的回复。我试过没有用。仍然收到错误
  • 那么导致错误的实际请求 URI 是什么?你在浏览器中输入什么来获取你列出的 index.html?
  • @Gralgrathor 我输入 www.example.com/platform-client/server/www 以查看 index.html
  • 对,所以您的 docroot 就在您列出的文件夹结构的顶部。这意味着 应该指向相对于该 docroot 的位置。例如。 。或者我会这么认为。除非你的 .htaccess 中有更多的重写。

标签: php apache .htaccess ushahidi


【解决方案1】:

所以,要解决这个问题,请将以下 A 记录添加到您的 DNS 条目中:

*    A    <your host's ip-address>

您域的每个可能的子域现在都将指向同一个主机。您的托管服务提供商可能允许您通过某些配置面板(如 cpanel)添加 DNS 条目。如果他们这样做,请注意您所做的更改。提交错误的更改可能会使您的主机停播数小时。如果他们不允许“*”作为您的子域,那么只需输入您需要的特定子域。

然后,在您的 httpd.conf 中包含以下两个虚拟主机 - 理想情况下包含在 /etc/apache2/sites-enabled 文件夹中,但您可以担心稍后美化您的配置:

<VirtualHost *:80>
    ServerAdmin webmaster@<yourdomain>.com
    DocumentRoot /var/www/html
    ServerName www.<yourdomain>.com
    ServerAlias <yourdomain>.com
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@<yourdomain>.com
    DocumentRoot /var/www/html/platform-client/server/www
    ServerName <subdomain>.<yourdomain>.com
</VirtualHost>

理想情况下,您还应该将两个文件夹结构分开,使它们看起来像这样:

/var
    /www
        /<yourdomain>.com
            /www
                /htdocs
                    index.html and everything
                        else for your default
                        website goes here
            /<subdomain>
                /htdocs
                    index.html and everything
                        else for your Ushithingy
                        installation goes here

并相应地调整虚拟主机中的 docroot。你应该这样做的原因是,只要一个网站在另一个网站的 docroot 中,仍然可以通过第一个虚拟主机定义访问第二个网站 - 只有这样页面才会因为不同而看起来一团糟docroot 和页面中的绝对 href。有序目录结构的另一个优点是您可以使用 mod_vhost_alias 通过一个简单的虚拟主机定义为许多子域定义网站。但同样,那是以后的事了。

如果你完成了,重启你的 apache 服务器,应该一切都好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-17
    • 1970-01-01
    • 1970-01-01
    • 2018-05-25
    • 2016-09-11
    • 2015-04-19
    • 2021-05-24
    • 1970-01-01
    相关资源
    最近更新 更多