繁体   English   中英

404未找到; Apache Server无法加载简单的php文件

[英]404 Not Found; Apache Server can't load simple php file

因此,我得到了一个静态站点。 它是用php构建的。 不幸的是我不熟悉。 但是,我认为应该关注的不多,因为我的目标只是尝试在本地提供服务,以便我可以对其进行更新。

这是网站所在的目录...

/Users/antonio-pavicevac-ortiz/Sites/

我用以下配置Apache。 (我使用的是macOS High Sierra 10.13.6。)

私人/等/主机

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
#127.0.0.1         localhost

127.0.0.1         fragrances.christinaaguilera
127.0.0.1         www.fragrances.christinaaguilera

255.255.255.255   broadcasthost
::1               localhost

/private/etc/apache2/httpd.conf

我认为这是最重要的改变...我错了吗?

DocumentRoot "/Users/antonio-pavicevac-ortiz/Sites/"
<Directory "/Users/antonio-pavicevac-ortiz/Sites/">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options FollowSymLinks Multiviews
    MultiviewsMatch Any

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

/private/etc/apache2/users/antonio-pavicevac-ortiz.conf

  <Directory "Users/antonio-pavicevac-ortiz/Sites/">
    Options Indexes MultiViews
    AllowOverride None
    Require all granted
  </Directory>

最后是config.php文件:

<?php

    // error_reporting(E_ALL);
    // ini_set("display_errors", 1);

    session_start();

    $validLanguages = array('EN'=>'en','DE'=>'de'/*,'RU'=>'ru','PT'=>'pt','HU'=>'hu','NL'=>'nl'*/);

    switch ($_SERVER['SERVER_NAME'])
    {


        case 'fragrances.christinaaguilera' || 'www.fragrances.christinaaguilera':
        {
            error_reporting(E_ALL);
            ini_set("display_errors", 1);

            if(substr($_SERVER['HTTP_HOST'],0,7)!='http://')
            {
                $_SERVER['HTTP_HOST']='http://'.$_SERVER['HTTP_HOST'];
            }

            define('ROOT_PATH',  '/Users/antonio-pavicevac-ortiz/Sites/fragrances.christinaaguilera.dev');
            define('TEMPLATE_PATH', ROOT_PATH.'templates/');
            define('XML_PATH',    ROOT_PATH.'xml/');
            define('ROOT_URL',    $_SERVER['HTTP_HOST'].'/');
            define('MEDIA_ROOT_URL','/');
            define('CSS_ROOT_URL',  MEDIA_ROOT_URL.'css/');
            define('JS_ROOT_URL',   MEDIA_ROOT_URL.'js/');
            define('IMG_ROOT_URL',  MEDIA_ROOT_URL.'images/');

            break;
        }
        // case'192.168.0.206':
        // {
        //  error_reporting(E_ALL);
        //  ini_set("display_errors", 1);
        //
        //  if(substr($_SERVER['HTTP_HOST'],0,7)!='http://')
        //  {
        //      $_SERVER['HTTP_HOST']='http://'.$_SERVER['HTTP_HOST'];
        //  }
        //
        //  define('ROOT_PATH',  '/media/sf_public_html/aguilera-microsite/branches/20141007_responsive/');
        //  define('TEMPLATE_PATH', ROOT_PATH.'templates/');
        //  define('XML_PATH',    ROOT_PATH.'xml/');
        //  define('ROOT_URL',    $_SERVER['HTTP_HOST'].'/aguilera-microsite/branches/20141007_responsive/');
        //  define('MEDIA_ROOT_URL','http://192.168.0.206/aguilera-microsite/branches/20141007_responsive/');
        //  define('CSS_ROOT_URL',  ROOT_URL.'css/');
        //  define('JS_ROOT_URL',   ROOT_URL.'js/');
        //  define('IMG_ROOT_URL',  ROOT_URL.'images/');
        //
        //  break;
        // }

        // case'137.183.87.135':
        // {
        //  error_reporting(E_ALL);
        //  ini_set("display_errors", 1);
        //
        //  if(substr($_SERVER['HTTP_HOST'],0,7)!='http://')
        //  {
        //      $_SERVER['HTTP_HOST']='http://'.$_SERVER['HTTP_HOST'];
        //  }
        //
        //  define('ROOT_PATH',  '/content/aguilera/docs/responsive/');
        //  define('TEMPLATE_PATH', ROOT_PATH.'templates/');
        //  define('XML_PATH',    ROOT_PATH.'xml/');
        //  define('ROOT_URL',    $_SERVER['HTTP_HOST'].'/responsive/');
        //  define('MEDIA_ROOT_URL','http://137.183.87.135:4064/content/aguilera/docs/responsive/');
        //  define('CSS_ROOT_URL',  ROOT_URL.'css/');
        //  define('JS_ROOT_URL',   ROOT_URL.'js/');
        //  define('IMG_ROOT_URL',  ROOT_URL.'images/');
        //
        //  break;
        // }

        //case'137.183.87.139':
        //{
        //  // error_reporting(E_ALL);
        //  // ini_set("display_errors", 1);
        //
        //  if(substr($_SERVER['HTTP_HOST'],0,7)!='http://')
        //  {
        //      $_SERVER['HTTP_HOST']='http://'.$_SERVER['HTTP_HOST'];
        //  }
        //
        //  define('ROOT_PATH',  '/content/aguilera/docs/restage/');
        //  define('TEMPLATE_PATH', ROOT_PATH.'templates/');
        //  define('XML_PATH',    ROOT_PATH.'xml/');
        //  define('ROOT_URL',    $_SERVER['HTTP_HOST'].'/restage/');
        //  define('MEDIA_ROOT_URL','http://137.183.87.139:4064/restage/');
        //  define('CSS_ROOT_URL',  MEDIA_ROOT_URL.'css/');
        //  define('JS_ROOT_URL',   MEDIA_ROOT_URL.'js/');
        //  define('IMG_ROOT_URL',  MEDIA_ROOT_URL.'images/');
        //
        //  break;
        //}

        //case'137.183.87.140':
        //{
        //  // error_reporting(E_ALL);
        //  // ini_set("display_errors", 1);
        //
        //  if(substr($_SERVER['HTTP_HOST'],0,7)!='http://')
        //  {
        //      $_SERVER['HTTP_HOST']='http://'.$_SERVER['HTTP_HOST'];
        //  }
        //
        //  define('ROOT_PATH',  '/content/aguilera/docs/restage/');
        //  define('TEMPLATE_PATH', ROOT_PATH.'templates/');
        //  define('XML_PATH',    ROOT_PATH.'xml/');
        //  define('ROOT_URL',    $_SERVER['HTTP_HOST'].'/restage/');
        //  define('MEDIA_ROOT_URL','http://137.183.87.140:4064/restage/');
        //  define('CSS_ROOT_URL',  MEDIA_ROOT_URL.'css/');
        //  define('JS_ROOT_URL',   MEDIA_ROOT_URL.'js/');
        //  define('IMG_ROOT_URL',  MEDIA_ROOT_URL.'images/');

        //  break;
        //}

        default:
        {
           // error_reporting(E_ALL);
           // ini_set("display_errors", 1);

            if(substr($_SERVER['HTTP_HOST'],0,7)!='http://')
            {
                $_SERVER['HTTP_HOST']='http://'.$_SERVER['HTTP_HOST'];
            }

            if(!preg_match('~elizabetharden~',$_SERVER['HTTP_HOST'])){
                // PROD instance root path
                define('ROOT_PATH',  'D:/Sites/wwwroot/fragrances.christinaaguilera.com/content/aguilera/docs/restage/');
            } else {
                // DEV instance root path
                define('ROOT_PATH',  'D:/Sites/wwwroot/christinaaguilera.elizabetharden.net/content/aguilera/docs/restage/');
            }

            define('TEMPLATE_PATH', ROOT_PATH.'templates/');
            define('XML_PATH',    ROOT_PATH.'xml/');
            define('ROOT_URL',    $_SERVER['HTTP_HOST'].'/');

            if(isset($_SERVER["HTTP_SSL"])){
                // define('MEDIA_ROOT_URL','https://secure.footprint.net/perfumes-christinaaguilera-com/restage/v_23/');
            } else {
                // define('MEDIA_ROOT_URL','http://media.perfumes.christinaaguilera.com/restage/v_23/');
            }

            define('MEDIA_ROOT_URL','/');

            define('CSS_ROOT_URL',  MEDIA_ROOT_URL.'css/');
            define('JS_ROOT_URL',   MEDIA_ROOT_URL.'js/');
            define('IMG_ROOT_URL',  MEDIA_ROOT_URL.'images/');

             break;
        }

    }

10月2日更新

所以我现在使用别名:

在此处输入图片说明

但是正如您所看到的,它指向Sites文件夹中的index.html文件。

在此处输入图片说明

而且我更新了/private/etc/apache2/httpd.conf

  <Directory "Users/antonio-pavicevac-ortiz/Sites/">
    AddLanguage en .en
    AddHandler perl-script .pl
    PerlHandler ModPerl::Registry
    Options Indexes MultiViews FollowSymLinks ExecCGI
    AllowOverride None
    Require host localhost
  </Directory>
  • 现在我可以运行Pearl脚本了... :)

根据msg 更新10月2日 ...

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot /Users/antonio-pavicevac-ortiz/Sites/fragrances.christinaaguilera/
    <Directory  "/Users/antonio-pavicevac-ortiz/Sites/">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/Users/antonio-pavicevac-ortiz/Sites/fragrances.christinaaguilera/"
    ServerName fragrances.christinaaguilera
    ServerAlias www.fragrances.christinaaguilera
    <Directory  "/Users/antonio-pavicevac-ortiz/Sites/fragrances.christinaaguilera/">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

我最新的config.php

<?php

    // error_reporting(E_ALL);
    // ini_set("display_errors", 1);

    session_start();

    $validLanguages = array('EN'=>'en','DE'=>'de'/*,'RU'=>'ru','PT'=>'pt','HU'=>'hu','NL'=>'nl'*/);

    switch ($_SERVER['SERVER_NAME'])
    {


        case 'fragrances.christinaaguilera' || 'www.fragrances.christinaaguilera':
        {
            error_reporting(E_ALL);
            ini_set("display_errors", 1);

            if(substr($_SERVER['HTTP_HOST'],0,7)!='http://')
            {
                $_SERVER['HTTP_HOST']='http://'.$_SERVER['HTTP_HOST'];
            }

            define('ROOT_PATH',  '/Users/antonio-pavicevac-ortiz/Sites/fragrances.christinaaguilera/');
            define('TEMPLATE_PATH', ROOT_PATH.'templates/');
            define('XML_PATH',    ROOT_PATH.'xml/');
            define('ROOT_URL',    $_SERVER['HTTP_HOST'].'/');
            define('MEDIA_ROOT_URL','/');
            define('CSS_ROOT_URL',  MEDIA_ROOT_URL.'css/');
            define('JS_ROOT_URL',   MEDIA_ROOT_URL.'js/');
            define('IMG_ROOT_URL',  MEDIA_ROOT_URL.'images/');

            break;
        }
        // case'192.168.0.206':
        // {
        //  error_reporting(E_ALL);
        //  ini_set("display_errors", 1);
        //
        //  if(substr($_SERVER['HTTP_HOST'],0,7)!='http://')
        //  {
        //      $_SERVER['HTTP_HOST']='http://'.$_SERVER['HTTP_HOST'];
        //  }
        //
        //  define('ROOT_PATH',  '/media/sf_public_html/aguilera-microsite/branches/20141007_responsive/');
        //  define('TEMPLATE_PATH', ROOT_PATH.'templates/');
        //  define('XML_PATH',    ROOT_PATH.'xml/');
        //  define('ROOT_URL',    $_SERVER['HTTP_HOST'].'/aguilera-microsite/branches/20141007_responsive/');
        //  define('MEDIA_ROOT_URL','http://192.168.0.206/aguilera-microsite/branches/20141007_responsive/');
        //  define('CSS_ROOT_URL',  ROOT_URL.'css/');
        //  define('JS_ROOT_URL',   ROOT_URL.'js/');
        //  define('IMG_ROOT_URL',  ROOT_URL.'images/');
        //
        //  break;
        // }

        // case'137.183.87.135':
        // {
        //  error_reporting(E_ALL);
        //  ini_set("display_errors", 1);
        //
        //  if(substr($_SERVER['HTTP_HOST'],0,7)!='http://')
        //  {
        //      $_SERVER['HTTP_HOST']='http://'.$_SERVER['HTTP_HOST'];
        //  }
        //
        //  define('ROOT_PATH',  '/content/aguilera/docs/responsive/');
        //  define('TEMPLATE_PATH', ROOT_PATH.'templates/');
        //  define('XML_PATH',    ROOT_PATH.'xml/');
        //  define('ROOT_URL',    $_SERVER['HTTP_HOST'].'/responsive/');
        //  define('MEDIA_ROOT_URL','http://137.183.87.135:4064/content/aguilera/docs/responsive/');
        //  define('CSS_ROOT_URL',  ROOT_URL.'css/');
        //  define('JS_ROOT_URL',   ROOT_URL.'js/');
        //  define('IMG_ROOT_URL',  ROOT_URL.'images/');
        //
        //  break;
        // }

        //case'137.183.87.139':
        //{
        //  // error_reporting(E_ALL);
        //  // ini_set("display_errors", 1);
        //
        //  if(substr($_SERVER['HTTP_HOST'],0,7)!='http://')
        //  {
        //      $_SERVER['HTTP_HOST']='http://'.$_SERVER['HTTP_HOST'];
        //  }
        //
        //  define('ROOT_PATH',  '/content/aguilera/docs/restage/');
        //  define('TEMPLATE_PATH', ROOT_PATH.'templates/');
        //  define('XML_PATH',    ROOT_PATH.'xml/');
        //  define('ROOT_URL',    $_SERVER['HTTP_HOST'].'/restage/');
        //  define('MEDIA_ROOT_URL','http://137.183.87.139:4064/restage/');
        //  define('CSS_ROOT_URL',  MEDIA_ROOT_URL.'css/');
        //  define('JS_ROOT_URL',   MEDIA_ROOT_URL.'js/');
        //  define('IMG_ROOT_URL',  MEDIA_ROOT_URL.'images/');
        //
        //  break;
        //}

        //case'137.183.87.140':
        //{
        //  // error_reporting(E_ALL);
        //  // ini_set("display_errors", 1);
        //
        //  if(substr($_SERVER['HTTP_HOST'],0,7)!='http://')
        //  {
        //      $_SERVER['HTTP_HOST']='http://'.$_SERVER['HTTP_HOST'];
        //  }
        //
        //  define('ROOT_PATH',  '/content/aguilera/docs/restage/');
        //  define('TEMPLATE_PATH', ROOT_PATH.'templates/');
        //  define('XML_PATH',    ROOT_PATH.'xml/');
        //  define('ROOT_URL',    $_SERVER['HTTP_HOST'].'/restage/');
        //  define('MEDIA_ROOT_URL','http://137.183.87.140:4064/restage/');
        //  define('CSS_ROOT_URL',  MEDIA_ROOT_URL.'css/');
        //  define('JS_ROOT_URL',   MEDIA_ROOT_URL.'js/');
        //  define('IMG_ROOT_URL',  MEDIA_ROOT_URL.'images/');

        //  break;
        //}

        default:
        {
           // error_reporting(E_ALL);
           // ini_set("display_errors", 1);

            if(substr($_SERVER['HTTP_HOST'],0,7)!='http://')
            {
                $_SERVER['HTTP_HOST']='http://'.$_SERVER['HTTP_HOST'];
            }

            if(!preg_match('~elizabetharden~',$_SERVER['HTTP_HOST'])){
                // PROD instance root path
                define('ROOT_PATH',  'D:/Sites/wwwroot/fragrances.christinaaguilera.com/content/aguilera/docs/restage/');
            } else {
                // DEV instance root path
                define('ROOT_PATH',  'D:/Sites/wwwroot/christinaaguilera.elizabetharden.net/content/aguilera/docs/restage/');
            }

            define('TEMPLATE_PATH', ROOT_PATH.'templates/');
            define('XML_PATH',    ROOT_PATH.'xml/');
            define('ROOT_URL',    $_SERVER['HTTP_HOST'].'/');

            if(isset($_SERVER["HTTP_SSL"])){
                // define('MEDIA_ROOT_URL','https://secure.footprint.net/perfumes-christinaaguilera-com/restage/v_23/');
            } else {
                // define('MEDIA_ROOT_URL','http://media.perfumes.christinaaguilera.com/restage/v_23/');
            }

            define('MEDIA_ROOT_URL','/');

            define('CSS_ROOT_URL',  MEDIA_ROOT_URL.'css/');
            define('JS_ROOT_URL',   MEDIA_ROOT_URL.'js/');
            define('IMG_ROOT_URL',  MEDIA_ROOT_URL.'images/');

             break;
        }

    }

Apache会将请求路由到首先匹配ServerNameServerAliasVirtualHost ,或者将其标记为_default_或第一个定义的VirtualHost如果不存在)。 基于此,可以从该VirtualHostDocumentRoot目录或没有文件定义的DirectoryIndex提供请求的任何文件。

因此,到目前为止,给定(已知)目录结构,您需要进行以下配置:

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot /Users/antonio-pavicevac-ortiz/Sites/
    <Directory  "/Users/antonio-pavicevac-ortiz/Sites/">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/Users/antonio-pavicevac-ortiz/Sites/fragrances.christinaaguilera/"
    ServerName fragrances.christinaaguilera
    ServerAlias www.fragrances.christinaaguilera
    <Directory  "/Users/antonio-pavicevac-ortiz/Sites/fragrances.christinaaguilera/">
        Options +Indexes +Includes +FollowSymLinks -MultiViews
        AllowOverride None
        DirectoryIndex rootfile.php
        Require local
    </Directory>
</VirtualHost>

请注意,我更改了MultiViewsAllowOverrideDirectoryIndex设置。

现在,当您访问http://fragrances.christinaaguilera Apache通常会尝试提供index.html或类似文件,但使用DirectoryIndex则会提供该文件。 使用AllowOverride All ,它将检查.htaccess是否存在并在其中应用规则,但我现在已将其禁用。 我们将一次迈出一步。

您可以通过执行apachectl -D DUMP_VHOSTS来检查apache是​​否正在获取您的配置。 它应该向您显示已定义的VirtualHosts 如果没有,请通过查找如下的Include指令,确保虚拟主机配置文件包含在主httpd.conf服务器配置中:

Include /private/etc/apache2/extra/httpd-vhosts.conf
Include /private/etc/apache2/extra/*.conf

确保路径匹配,然后重新启动服务。

一旦VirtualHost启动并运行,就可以获取.htaccess 为此,我们需要改回AllowOverride并摆脱DirectoryIndex指令,而将VirtualHostDirectory保留如下:

<Directory  "/Users/antonio-pavicevac-ortiz/Sites/fragrances.christinaaguilera/">
    Options +Indexes +Includes +FollowSymLinks -MultiViews
    AllowOverride All
    Require local
</Directory>

现在,在访问站点时,我们应该会看到相同的重定向行为。 幸运的是,我们将看到该站点。 如果没有,我们将首先注释掉RewriteBase /restage行。

大多数的文件不应该为我们的宗旨是必要的。 认为我们可以从这个最小的版本开始:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /rootfile.php/$1 [L]   

这是一个非常标准的干净的URL路由器设置。 它转换为“将不是磁盘上的物理文件或目录的任何请求重定向到rootfile.php / uri”。

现在尝试访问http://fragrances.christinaaguilera/en/

以下是文件其余部分的细分:

  • AddType指令告诉apache发送那些特定文件扩展名的mime标头。 如果运行现代版本的apache,则可能不需要它们,但是请确保...

  • RewriteCond %{HTTP_HOST}行和随后的RewriteRule重定向到规范网址(www。版本)。 除非要确保没有多余的重定向,否则在开发中没有太大意义。

  • 所有您不需要的RewriteRule hu/$ /en/ [R=301,L] ,因为它是在php端处理的( if(!in_array($language, $validLanguages)) )。 他们重定向到英语版本。 除了/de/ ,它仍在使用。 为了安全起见,还应在其中保留lang/home$重定向。

最后是三个潜在的问题行:

RewriteBase /restage/
RewriteCond %{REQUEST_URI} !microsite
RewriteRule ^(.*)v_([0-9]*)/(.*)$ /restage/$3 [L]

无法确定在内部链接中没有更多信息的情况下他们会怎么做,但这就是它们的含义:

  • RewriteBase基本上说“对于发生的任何重写,请在/restage/之前添加”。 这是文件范围的文件,因此也会影响rootfile.php重定向。 因此,它应该是项目内部的restage目录,(主要是)相同的文件才能使此规则有意义。
  • 以下两条规则翻译成V - “这不是一个微型包含字符串的任何要求‘’后面的数字和一个斜杠和任何字符串,重定向到/重演/重演/ any_string”。 由于存在/restages ,因此翻译中有两个/restages RewriteBase 这种行为让我最担心,但是正如我所说,需要有关项目结构的更多信息。 似乎有人正在努力向网站副本中添加一些功能。

如果使用.htaccess功能,则需要在Apache服务器上启用mod_rewrite。 要对此进行检查,请运行以下命令:

sudo apache2ctl -M

如果您在列表中看到rewrite_module,那就很好了。 如果没有,只需使用以下命令启用它:

sudo a2enmod rewrite

并重新启动Apache以使更改生效:

sudo service apache2 restart

您必须在定义主机名和文档根目录的地方声明虚拟主机。

将以下内容添加到httpd.conf的末尾,然后重新启动apache:

<Directory "/Users/antonio-pavicevac-ortiz/Sites/fragrances.christinaaguilera/"> 
  Options Indexes MultiViews
  AllowOverride All
</Directory>

NameVirtualHost *:80 

<VirtualHost *:80>
  DocumentRoot "/Users/antonio-pavicevac-ortiz/Sites/fragrances.christinaaguilera"
  ServerName fragrances.christinaaguilera
  ServerAlias www.fragrances.christinaaguilera
</VirtualHost>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM