我从https://github.com/crjoseabraham/php-mvc开始就遵循了基础项目 struct 在此基础上,我创建了一个php MVC项目,该项目在开发服务器AWS EC2上运行良好.我面临着绑定域名后的重定向问题.

我在Apache2.conf中为绑定域应用了以下更改.

<VirtualHost *:80>
    ServerName subdomain.mydomain.com
    ServerAlias www.subdomain.mydomain.com
    DocumentRoot /var/www/html/project-1/public
    <Directory /var/www/html/project-1/public>

        AllowOverride All
        Require all granted
    </Directory>

ErrorLog ${APACHE_LOG_DIR}/subdomain.mydomain.com_error.log
CustomLog ${APACHE_LOG_DIR}/subdomain.mydomain.com_access.log combined
</VirtualHost>

我的项目 struct :

enter image description here

根目录.htaccess文件的代码如下:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^$ public/ [L]
    RewriteRule (.*) public/$1 [L]
</IfModule>

公共目录.htaccess代码为:

<IfModule mod_rewrite.c>
        Options -Multiviews
    RewriteEngine On
    RewriteBase /project-1/public
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
   
    RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
 
</IfModule>

所以,在应用上述更改后,我可以使用域名访问我的项目,它会成功打开登录页面.但当我点击菜单时,我得到的是错误信息:

内部服务器错误

服务器遇到内部错误或配置错误,并且 无法完成您的请求.

请通过[未提供地址]联系服务器管理员 告知他们此错误发生的时间,以及您采取的操作 恰好在此错误之前执行.

有关此错误的详细信息,请参阅服务器错误 原木.

为了解决这个问题,我在一个公共的.htaccess文件中应用了许多更改,但无法解决它.那么,你能帮我解决这个问题吗?

以下是我try 过的一些改变:

RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ public/index.php?url=$1 [QSA,L]

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase //

    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

apache 错误日志(log):

AH00124:由于可能的配置错误,请求超过了10个内部重定向的限制.如有必要,使用‘LimitInternalRecursion’增加限制.使用‘LogLevel DEBUG’获取回溯.,Referer:http://subdomain.mydomain.com/

推荐答案

DocumentRoot /var/www/html/project-1/public

由于您已经将DocumentRoot设置为直接指向public子目录,因此您应该完全删除第一个.htaccess文件(您称之为"根目录.htaccess文件"的文件--但它不是"根目录",它在根目录above中!)

然后,您只需要public目录内的单个.htaccess文件(它是"根目录")和整个remove the 102 directive目录内的remove the 102 directive文件(您的设置不正确,可能会导致重写循环500错误).

例如:

# The public (root) directory .htaccess file

Options -MultiViews

DirectoryIndex index.php

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f   
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

<IfModule>的包装纸也应该go 掉.

相对替换字符串相对于包含.htaccess文件的目录重写请求.这里用不着用RewriteBase.

Php相关问答推荐

根据用户组或登录状态显示或隐藏定价后添加的文本

过滤WooCommerce管理员订单列表(+HPOS)中包含其作者产品的订单

将变体设置字段添加到WooCommerce中的特定变量产品

将购买限制在WooCommerce中具有相同产品属性的项目

在WordPress中从CPT中删除插件

上传WordPress模板中的翻译文件(.mo和.po)

升级到PHP 8.2后无法删除cURL Cookie文件

fpm-php + nginx + POST数据

无法允许元素(img:'src')与symfony html-sanitizer(symfony6.3 php 8.2)

如何用十进制和字母数字减go 和添加 id

如何在 Phpunit 的静态提供程序中创建测试双打?

Laravel Eloquent(where 子句)

避免在 WooCommerce 中多次触发挂钩函数

如何使用不同的方法编写嵌套连接查询并将两列连接成一列在 laravel 查询生成器中

来自 GoDaddy 的邮箱在 Gmail 中显示为via

使用 PHP 正则表达式从仅包含具有现有顺序的顶级标签的 XML 文档中搜索和创建数组

在 DomPDF 和 Laravel 中使用内联 css

mysql / sql修复多对多数据库中的行

Laravel - 关联与设置观察者事件的 ID

如何简化 php API 中的格式化数组列表数据以提供 React Native 部分列表