所以给了我一个静态站点。它是用php构建的。不幸的是我不熟悉。但是,我认为应该关注的不多,因为我的目标只是尝试在本地提供服务,以便我可以对其进行更新。
这是网站所在的目录...
/Users/antonio-pavicevac-ortiz/Sites/
我用以下配置Apache。 (我使用的是macOS High Sierra 10.13.6。)
私有/ etc /主机
##
# 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>
根据味精更新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;
}
}
答案 0 :(得分:2)
Apache会将请求路由到首先匹配VirtualHost
或ServerName
的{{1}},或者将标记为ServerAlias
或第一个_default_
的匹配的路由不是一个。基于此,可以从VirtualHost
目录的DocumentRoot
或如果没有文件定义的VirtualHost
的目录中请求任何文件。
因此,到目前为止,鉴于您的(已知)目录结构,您需要进行以下配置:
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
时,Apache通常会尝试提供http://fragrances.christinaaguilera
或类似文件,但是使用index.html
会代替该文件。使用DirectoryIndex
,它将检查AllowOverride All
是否存在,并在其中应用规则,但是我暂时将其禁用。我们将一次迈出一步。
您可以通过执行.htaccess
来检查apache是否正在获取您的配置。它应该向您显示已定义的apachectl -D DUMP_VHOSTS
。如果没有,请通过查找VirtualHosts
伪指令来确保虚拟主机配置文件包含在主httpd.conf
服务器配置中,例如:
Include
确保路径匹配并重新启动服务。
一旦我们启动Include /private/etc/apache2/extra/httpd-vhosts.conf
Include /private/etc/apache2/extra/*.conf
并开始运行,就可以开始VirtualHost
了。为此,我们需要改回.htaccess
并摆脱AllowOverride
指令,而将DirectoryIndex
留给Directory
就像这样:
VirtualHost
现在,访问站点时,我们应该会看到相同的重定向行为。幸运的是,我们将看到该站点。如果没有,我们将首先注释掉行<Directory "/Users/antonio-pavicevac-ortiz/Sites/fragrances.christinaaguilera/">
Options +Indexes +Includes +FollowSymLinks -MultiViews
AllowOverride All
Require local
</Directory>
。
对于我们而言,应该大多数文件不是必需的。我认为,我们可以从这个最小版本开始:
RewriteBase /restage
这是一个非常标准的干净URL路由器设置。它转换为“将不是磁盘上的物理文件或目录的任何请求重定向到rootfile.php / uri”。
现在尝试访问RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /rootfile.php/$1 [L]
。
以下是该文件其余部分的细目:
http://fragrances.christinaaguilera/en/
指令告诉apache发送那些特定文件扩展名的mime标头。如果运行现代版本的apache,则可能不需要它们,但是请确保...
AddType
行和RewriteCond %{HTTP_HOST}
之后的行重定向到规范网址(www。版本)。除非要确保没有多余的重定向,否则在开发中没有太大意义。
您不需要的所有RewriteRule
,因为它是在php端(RewriteRule hu/$ /en/ [R=301,L]
)处理的。他们重定向到英语版本。除了if(!in_array($language, $validLanguages))
之外,它一直在使用。另外,为了安全起见,还保留了/de/
重定向。
最后是三个可能有问题的行:
lang/home$
如果不确定内部链接中没有更多信息,他们将做什么,但这是它们的含义:
RewriteBase /restage/
RewriteCond %{REQUEST_URI} !microsite
RewriteRule ^(.*)v_([0-9]*)/(.*)$ /restage/$3 [L]
基本上说“对于发生的任何重写,请在其之前加上RewriteBase
”。这是文件范围的文件,因此也会影响/restage/
重定向。因此,应该是您项目中的restage目录,其中包含(大部分)相同的文件,对此规则有意义。rootfile.php
,翻译中有两个/restages
。这种行为让我最担心,但是正如我所说,需要有关项目结构的更多信息。似乎有人正在努力向网站副本中添加一些功能。答案 1 :(得分:0)
如果使用.htaccess功能,则需要在Apache服务器上启用mod_rewrite。要对此进行检查,请运行以下命令:
sudo apache2ctl -M
如果您在列表中看到rewrite_module,那就很好了。如果没有,只需使用以下命令启用它:
sudo a2enmod rewrite
然后重新启动Apache以使更改生效:
sudo service apache2 restart
答案 2 :(得分:0)
您必须在定义主机名和文档根目录的地方声明虚拟主机。
在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>