Fat Free 框架中 mod_rewrite 的简单问题

2023-01-18php开发问题
6

本文介绍了Fat Free 框架中 mod_rewrite 的简单问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试为 PHP 设置和学习 Fat Free 框架.http://fatfree.sourceforge.net/

I am trying to setup and learn the Fat Free Framework for PHP. http://fatfree.sourceforge.net/

设置相当简单,我使用 MAMP 在我的机器上运行它.

It's is fairly simple to setup and I am running it on my machine using MAMP.

我能够让 'hello world' 示例仅在 fin 上运行:

I was able to get the 'hello world' example running just fin:

require_once 'path/to/F3.php';
F3::route('GET /','home');
    function home() {
        echo 'Hello, world!';
    }
F3::run();

但是当我尝试添加有两条路线的第二部分时:

But when I try to add in the second part, which has two routes:

require_once 'F3/F3.php';

require_once 'F3/F3.php';

F3::route('GET /','home');
function home() {
    echo 'Hello, world!';
}

F3::route('GET /about','about');
function about()
{
    echo 'About Us.';
}

F3::run();

如果我尝试第二个 URL:/about

I get a 404 error if I try the second URL: /about

不确定为什么 mod_rewrite 命令中的一个会起作用,而另一个不起作用.

Not sure why one of the mod_rewrite commands would be working and not the other.

下面是我的 .htaccess 文件:

# Enable rewrite engine and route requests to framework
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L,QSA]

# Disable ETags
Header Unset ETag
FileETag none

# Default expires header if none specified (stay in browser cache for 7 days)
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A604800
</IfModule>

推荐答案

所以我的朋友实际上帮我解决了这个问题.我遇到了完全相同的问题,但基本上我也在使用 MAMP,并且在 MAMP 的 htdocs 中的 fatfree 目录中保存了我所有的 Fat Free 文件.

So my friend actually helped me out with this issue. I ran into the exact same problem, but basically I'm using MAMP also and have all my Fat Free files within a fatfree dir within htdocs of MAMP.

解决方案是您需要修改 RewriteBase 以指向 /[dirname]/ 而不仅仅是 / 然后更改 RewriteRule/[dirname]/index.php.

The solution is you need to mod the RewriteBase to point to /[dirname]/ instead of just / and then change RewriteRule to /[dirname]/index.php.

我的 .htaccess 如下所示:

My .htaccess looks like this:

RewriteEngine On
RewriteBase /fatfree/
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /fatfree/index.php [L,QSA]

设置后,您可以完全按照 Fat Free 文档中的示例进行操作,它会像魅力一样发挥作用.这让我难住了一段时间,这就是它所需要的.此外,如果您使用 MAMP,请编辑 /Applications/MAMP/conf/apache 中的 httpd.conf 文件,并确保更改以下内容:

After that's set, you can follow the example in the Fat Free doc exactly and it'll work like a charm. This stumped me for a while and this was all it needed. Also, if you're using MAMP, edit the httpd.conf file in /Applications/MAMP/conf/apache and be sure to alter the following:

<Directory />
    Options Indexes FollowSymLinks
    AllowOverride None
</Directory>

<Directory />
    Options Indexes FollowSymLinks
    AllowOverride All
</Directory>

基本上把None改成All.

这篇关于Fat Free 框架中 mod_rewrite 的简单问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17