[英]Apache - Error 404 calling REST API /codeguard/users - PHP Laravel - CentOS 7
我正在尝试使用 1 个 IP 托管 2 个网站,站点使用 Laravel PHP 路由,所以我使用了 Apache Alias 方法和虚拟主机:
<VirtualHost *:443 >
# General setup for the virtual host, inherited from global configuration
DocumentRoot "/var/www/html/"
Alias "/development" "/var/www/html/develop/public"
Alias "/staging" "/var/www/html/staging/public"
# Use separate log files for the SSL virtual host; note that LogLevel
# is not inherited from httpd.conf.
ErrorLog /var/log/httpd/prod_ssl_error_log
TransferLog /var/log/httpd/prod_ssl_access_log
LogLevel warn
<Directory "/var/www/html/develop/public">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
SSLCertificateFile /etc/ssl/private/1.crt
SSLCertificateKeyFile /etc/ssl/private/1.key
</VirtualHost>
<VirtualHost *:443 >
DocumentRoot "/var/www/html/staging/public"
ErrorLog /var/log/httpd/staging_ssl_error_log
TransferLog /var/log/httpd/staging_ssl_access_log
LogLevel warn
<Directory "/var/www/html/staging/public">
DirectoryIndex index.php
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
SSLCertificateFile /etc/ssl/private/1.crt
SSLCertificateKeyFile /etc/ssl/private/1.key
</VirtualHost>
两个站点都有包含 index.php 和 .htaccess 文件的公共文件夹
.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
Options +FollowSymLinks
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteBase /~development
RewriteCond $1 !^index\.php/
RewriteRule ^(.*)$ index.php/$1 [L]
当访问https://server/development和https://server/staging一切正常时,我得到了 php 页面
但如果尝试 https:/server/development/codeguard/users 我收到错误 404 和日志文件
文件不存在: /var/www/html/develop/public/codeguard/users
codeguard/users 确实不存在,但如果我删除 Alias 指令它工作正常
如果我尝试https://server/development/index.php/codeguard/users/然后它工作
但是,如果将多个 IP 分配给 Apache Web 服务器并将这 2 个地址分别绑定到每个虚拟主机,我没有任何问题 - 非别名 url
我需要使 https:/server/development/codeguard/users 链接有效(没有 index.php)
我想我需要为两个站点编辑 .httacess 文件,但不知道需要做什么。
任何帮助/提示都非常感谢。
编辑:
我通过编辑 .htaccess 文件使其适用于第一个虚拟主机(开发):
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
Options +FollowSymLinks
RewriteEngine On
RewriteBase "/development/"
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
# RewriteRule ^ %1 [L,R=301]
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !^index\.php/
#RewriteRule ^(.*)$ index.php/$1 [L]
RewriteRule ^ index.php [L]
</IfModule>
但是对第二个站点(“/staging”)使用相同的配置失败并出现相同的错误 404
终于让它工作了,错误在 /etc/httpd/conf.d/ssl.conf 文件中,我有 2 个<Virtual Host *:443>
指令,应该只定义一个,否则“第二个”站点的 .htaccess 将被忽略
<VirtualHost *:443>
# General setup for the virtual host, inherited from global configuration
DocumentRoot "/var/www/html"
#ServerName www.example.com:443
# Use separate log files for the SSL virtual host; note that LogLevel
# is not inherited from httpd.conf.
ErrorLog logs/ssl_error_log
TransferLog logs/ssl_access_log
LogLevel debug
<Directory "/var/www/html/develop/public">
DirectoryIndex index.php
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Alias "/development" "/var/www/html/develop/public"
<Directory "/var/www/html/staging/public">
DirectoryIndex index.php
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Alias "/staging" "/var/www/html/staging/public"
</VirtualHost>
然后两个站点的 .htaccess 开始工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.