Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 带有目录的Apache虚拟主机uri_Php_Apache_Vhosts - Fatal编程技术网

Php 带有目录的Apache虚拟主机uri

Php 带有目录的Apache虚拟主机uri,php,apache,vhosts,Php,Apache,Vhosts,我无法在带有子目录的url上设置虚拟主机。。。 我需要在以下地址运行我的项目: NameVirtualHost *:80 <VirtualHost *:80> DocumentRoot "D:/Projects/Project1/public/" ServerName www.projects.loc/project1/ </VirtualHost> RewriteEngine On RewriteCond %{REQUEST_FI

我无法在带有子目录的url上设置虚拟主机。。。 我需要在以下地址运行我的项目:

NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot "D:/Projects/Project1/public/"         
    ServerName  www.projects.loc/project1/
</VirtualHost>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php [NC,L]
<VirtualHost *:80>
  ServerName projects.loc
  ServerAlias www.projects.loc
  ServerPath /project1/
  DocumentRoot /PATH/public_html
  ErrorLog /PATH/error_log
  CustomLog /PATH/access_log combined
  DirectoryIndex index.html index.htm index.php index.php4 index.php5

  <Directory /PATH/public_html>
    Options -Indexes +IncludesNOEXEC +FollowSymLinks
    allow from all
  </Directory>

</VirtualHost>
<VirtualHost *:80>
  ServerName projects.loc
  ServerAlias www.projects.loc
  DocumentRoot /PATH/public_html
  ErrorLog /PATH/error_log
  CustomLog /PATH/access_log combined
  DirectoryIndex index.html index.htm index.php index.php4 index.php5

  <Directory /PATH/public_html>
    Options -Indexes +IncludesNOEXEC +FollowSymLinks
    allow from all
  </Directory>

  Alias /project1 "/PATH/public_html/project1"
  <Directory "/PATH/public_html/project1">
    DirectoryIndex index.html index.htm index.php index.php4 index.php5
    Options -Indexes +IncludesNOEXEC +FollowSymLinks
    allow from all
  </Directory>

  Alias /project2 "/PATH/public_html/project2"
  <Directory "/PATH/public_html/project2">
    DirectoryIndex index.html index.htm index.php index.php4 index.php5
    Options -Indexes +IncludesNOEXEC +FollowSymLinks
    allow from all
  </Directory>

</VirtualHost>
http://www.projects.loc/project1/
这应该模拟在web服务器上的安装,地址如下

http://www.someServer.com/projects/project1/

我需要将重定向调整为“/”,以便它返回到
www.projects.loc/project1/

在hosts.txt中,我有:

127.0.0.1       www.projects.loc
vhosts已启用,httpd-vhosts.conf如下所示:

NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot "D:/Projects/Project1/public/"         
    ServerName  www.projects.loc/project1/
</VirtualHost>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php [NC,L]
<VirtualHost *:80>
  ServerName projects.loc
  ServerAlias www.projects.loc
  ServerPath /project1/
  DocumentRoot /PATH/public_html
  ErrorLog /PATH/error_log
  CustomLog /PATH/access_log combined
  DirectoryIndex index.html index.htm index.php index.php4 index.php5

  <Directory /PATH/public_html>
    Options -Indexes +IncludesNOEXEC +FollowSymLinks
    allow from all
  </Directory>

</VirtualHost>
<VirtualHost *:80>
  ServerName projects.loc
  ServerAlias www.projects.loc
  DocumentRoot /PATH/public_html
  ErrorLog /PATH/error_log
  CustomLog /PATH/access_log combined
  DirectoryIndex index.html index.htm index.php index.php4 index.php5

  <Directory /PATH/public_html>
    Options -Indexes +IncludesNOEXEC +FollowSymLinks
    allow from all
  </Directory>

  Alias /project1 "/PATH/public_html/project1"
  <Directory "/PATH/public_html/project1">
    DirectoryIndex index.html index.htm index.php index.php4 index.php5
    Options -Indexes +IncludesNOEXEC +FollowSymLinks
    allow from all
  </Directory>

  Alias /project2 "/PATH/public_html/project2"
  <Directory "/PATH/public_html/project2">
    DirectoryIndex index.html index.htm index.php index.php4 index.php5
    Options -Indexes +IncludesNOEXEC +FollowSymLinks
    allow from all
  </Directory>

</VirtualHost>
应用程序在干净的域上正常运行,但我无法将其配置为 在domain.com/some_dir上运行/

编辑:
解决了这个问题

NameVirtualHost *:80   

   <Directory "D:/Projects"> 
      allow from all
   </Directory>

    <VirtualHost *:80>
        DocumentRoot "D:/Projects"      
        ServerName  www.projects.loc/

        Alies /project1  /Project1/public/
    </VirtualHost>
NameVirtualHost*:80
通融
DocumentRoot“D:/Projects”
服务器名www.projects.loc/
Alies/project1/project1/public/
注意:这是仅适用于开发环境的最低配置,

查看@M-z接受的回复,了解生产环境的全部细节。

可能您已经解决了这个问题。无论如何,我今天看到的是类似的事情,因此我在这里记录了解决方案:

您不想在ServerName ServerName www.projects.loc/project1中写入斜杠/

ServerName www.projects.loc/project1/ 如果您只有一个名为“project1”的项目,您可以轻松地使用“ServerPath”完成任务,那么您的vhost配置将如下所示:

NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot "D:/Projects/Project1/public/"         
    ServerName  www.projects.loc/project1/
</VirtualHost>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php [NC,L]
<VirtualHost *:80>
  ServerName projects.loc
  ServerAlias www.projects.loc
  ServerPath /project1/
  DocumentRoot /PATH/public_html
  ErrorLog /PATH/error_log
  CustomLog /PATH/access_log combined
  DirectoryIndex index.html index.htm index.php index.php4 index.php5

  <Directory /PATH/public_html>
    Options -Indexes +IncludesNOEXEC +FollowSymLinks
    allow from all
  </Directory>

</VirtualHost>
<VirtualHost *:80>
  ServerName projects.loc
  ServerAlias www.projects.loc
  DocumentRoot /PATH/public_html
  ErrorLog /PATH/error_log
  CustomLog /PATH/access_log combined
  DirectoryIndex index.html index.htm index.php index.php4 index.php5

  <Directory /PATH/public_html>
    Options -Indexes +IncludesNOEXEC +FollowSymLinks
    allow from all
  </Directory>

  Alias /project1 "/PATH/public_html/project1"
  <Directory "/PATH/public_html/project1">
    DirectoryIndex index.html index.htm index.php index.php4 index.php5
    Options -Indexes +IncludesNOEXEC +FollowSymLinks
    allow from all
  </Directory>

  Alias /project2 "/PATH/public_html/project2"
  <Directory "/PATH/public_html/project2">
    DirectoryIndex index.html index.htm index.php index.php4 index.php5
    Options -Indexes +IncludesNOEXEC +FollowSymLinks
    allow from all
  </Directory>

</VirtualHost>

ServerName projects.loc
ServerAlias www.projects.loc
服务器路径/项目1/
DocumentRoot/PATH/public\u html
错误日志/路径/错误日志
自定义日志/路径/访问日志组合
DirectoryIndex.html index.htm index.php index.php4 index.php5
选项-索引+包含noexec+FollowSymLinks
通融
通过ServerPath,您可以将目录装载到projects.loc/project1

无论如何,假设您有多个项目(project1、project2)要绑定到projects.loc/project1、projects.loc/project2等。请使用“别名”。然后,vhost配置文件应如下所示:

NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot "D:/Projects/Project1/public/"         
    ServerName  www.projects.loc/project1/
</VirtualHost>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php [NC,L]
<VirtualHost *:80>
  ServerName projects.loc
  ServerAlias www.projects.loc
  ServerPath /project1/
  DocumentRoot /PATH/public_html
  ErrorLog /PATH/error_log
  CustomLog /PATH/access_log combined
  DirectoryIndex index.html index.htm index.php index.php4 index.php5

  <Directory /PATH/public_html>
    Options -Indexes +IncludesNOEXEC +FollowSymLinks
    allow from all
  </Directory>

</VirtualHost>
<VirtualHost *:80>
  ServerName projects.loc
  ServerAlias www.projects.loc
  DocumentRoot /PATH/public_html
  ErrorLog /PATH/error_log
  CustomLog /PATH/access_log combined
  DirectoryIndex index.html index.htm index.php index.php4 index.php5

  <Directory /PATH/public_html>
    Options -Indexes +IncludesNOEXEC +FollowSymLinks
    allow from all
  </Directory>

  Alias /project1 "/PATH/public_html/project1"
  <Directory "/PATH/public_html/project1">
    DirectoryIndex index.html index.htm index.php index.php4 index.php5
    Options -Indexes +IncludesNOEXEC +FollowSymLinks
    allow from all
  </Directory>

  Alias /project2 "/PATH/public_html/project2"
  <Directory "/PATH/public_html/project2">
    DirectoryIndex index.html index.htm index.php index.php4 index.php5
    Options -Indexes +IncludesNOEXEC +FollowSymLinks
    allow from all
  </Directory>

</VirtualHost>

ServerName projects.loc
ServerAlias www.projects.loc
DocumentRoot/PATH/public\u html
错误日志/路径/错误日志
自定义日志/路径/访问日志组合
DirectoryIndex.html index.htm index.php index.php4 index.php5
选项-索引+包含noexec+FollowSymLinks
通融
别名/project1“/PATH/public\u html/project1”
DirectoryIndex.html index.htm index.php index.php4 index.php5
选项-索引+包含noexec+FollowSymLinks
通融
别名/project2“/PATH/public\u html/project2”
DirectoryIndex.html index.htm index.php index.php4 index.php5
选项-索引+包含noexec+FollowSymLinks
通融
您的应用程序放置在文件夹/PATH/public_html/project1将在projects.loc/project1中可用,您的应用程序放置在文件夹/PATH/public_html/project2将在projects.loc/project2中可用,依此类推

我宁愿为不同的应用程序使用不同的子域。这样做的好处是,每个子域主机都有自己的配置文件,这也使得错误和访问日志处理更容易。如果希望每个应用程序都有不同的错误和访问日志,那么通过使用别名,配置不同的错误和访问日志将更加困难

进一步阅读:
关于别名:

关于ServerPath:

您尝试过哪些重写?我现在在查看您的ansler时解决了这个问题。。这是正确的,但要详细。。所以我第一次没拿到:)