[英]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>
根據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會將請求路由到首先匹配ServerName
或ServerAlias
的VirtualHost
,或者將其標記為_default_
或第一個定義的VirtualHost
如果不存在)。 基於此,可以從該VirtualHost
的DocumentRoot
目錄或沒有文件定義的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>
請注意,我更改了MultiViews
, AllowOverride
和DirectoryIndex
設置。
現在,當您訪問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
指令,而將VirtualHost
的Directory
保留如下:
<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目錄,(主要是)相同的文件才能使此規則有意義。 /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.