Apache - 错误 404 调用 REST API /codeguard/users - PHP Laravel - CentOS 7

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>

两个站点都有 public 个文件夹,其中包含 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  !^index\.php/
RewriteRule ^(.*)$ index.php/ [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 link 正常工作(没有 index.php)

我想我需要为两个站点编辑 .httacess 文件,但不知道需要做什么。

非常感谢help/hint。

编辑:

我通过编辑 .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 ^(.*)/$ / [L,R=301]


    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond  !^index\.php/
    #RewriteRule ^(.*)$ index.php/ [L]

    RewriteRule ^ index.php [L]

</IfModule>

但是对第二个站点(“/staging”)使用相同的配置失败并出现相同的错误 404

终于让它工作了,错误在 /etc/httpd/conf.d/ssl.conf 文件中,我有 2 个 <Virtual Host *:443> 指令,应该只定义一个,否则 .htaccess for "second" 网站被忽略

<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 开始工作