htaccess 导致下载index.php
我正在开发一个网站,该网站依赖于以下 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想您已经在开发服务器中为所有带有
*.php
扩展名的文件配置了 PHP。这意味着在.htaccess
文件中再次执行此操作不仅没有必要,而且可能会取消服务器的配置(正如它实际所做的那样)。因此,您需要删除这一行:问题是为什么它首先存在。我希望默认配置任何支持 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:The question is why it's there in the first place. I'd expect any PHP-enabled hosting service to be configured by default :-?