htaccess 导致下载index.php

发布于 2024-12-19 03:56:48 字数 593 浏览 1 评论 0原文

我正在开发一个网站,该网站依赖于以下 htaccess 文件来创建虚拟目录结构,只要系统上不存在指定的 url,就会重定向到 index.php。

AddHandler php5-script .php
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?p=$1 [L,QSA]

这似乎在客户端现有的服务器上运行良好。它无形地将诸如domain.com/checkout之类的内容重定向到domain.com/index.php?p=checkout

我的问题是,在我的本地开发环境中,这会导致任何不存在的URL(如domain.com/checkout),甚至是rootdomain.com 下载index.php

如果我尝试加载网站中存在的特定文件(例如domain.com/index.php),那么它会正确解析并显示在浏览器中。

以防万一,我的开发环境在 Zend Server Community Edition 上配置了虚拟主机。

I am working on a site that depends on the following htaccess file to create something of a virtual directory structure by redirecting to an index.php whenever the specified url doesn't exist on the system.

AddHandler php5-script .php
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?p=$1 [L,QSA]

That seems to work fine on the client's existing server. It invisibly redirects things like domain.com/checkout to domain.com/index.php?p=checkout

My problem is that on my local development environment, this causes any non-existing url like that domain.com/checkout, or even the root domain.com to DOWNLOAD the index.php

If I try to load a specific file that exists in the website such as domain.com/index.php then it parses and displays in the browser properly.

In case it matters, my development environment is configured with a Virtual Host on Zend Server Community Edition.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温馨耳语 2024-12-26 03:56:48

我想您已经在开发服务器中为所有带有 *.php 扩展名的文件配置了 PHP。这意味着在 .htaccess 文件中再次执行此操作不仅没有必要,而且可能会取消服务器的配置(正如它实际所做的那样)。因此,您需要删除这一行:

AddHandler php5-script .php

问题是为什么它首先存在。我希望默认配置任何支持 PHP 的托管服务:-?

I suppose you've already configured PHP in your development server for all files with the *.php extension. That means that doing it again in your .htaccess files is not only unnecessary but it can possibly cancel your server's configuration (as it's actually doing). Thus you need to get rid of this line:

AddHandler php5-script .php

The question is why it's there in the first place. I'd expect any PHP-enabled hosting service to be configured by default :-?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文