如何从地址中删除index.php,同时通过fastcgi将请求重定向到index.php?
我在 Ubuntu 服务器上有一个基本的 Magento(PHP 应用程序,使用 index.php 作为控制器)设置。我将 NGINX 配置为使用 PHP-CGI 来服务所有 PHP 页面。当网站按预期工作时,所有 URL 的形式如下:
http://domain.com/index.php/apparel/shoes.html
有没有办法使用 nginx rewrite 设置,以便我可以使用这样的 URL:
http://domain.com/apparel/shoes.html
目前,这就是我在配置文件中处理页面请求的内容:
# catch rewritten and standard URLs
location ~* ^(/index.php)?(.*) {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/index.php$1;
fastcgi_read_timeout 600;
}
谢谢。
I have a basic Magento (PHP app, using index.php as the controller) setup on an Ubuntu server. I configured NGINX to use PHP-CGI to serve all PHP pages. While the site is working as expected, all the URLs are of the form:
http://domain.com/index.php/apparel/shoes.html
Is there a way to use the nginx rewrite setting so that I can have the URLs like this instead:
http://domain.com/apparel/shoes.html
Currently, this is what I have in the configuration file to handle page requests:
# catch rewritten and standard URLs
location ~* ^(/index.php)?(.*) {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/index.php$1;
fastcgi_read_timeout 600;
}
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我在这方面对 nginx 有一些经验,甚至还写过相关文章。因此,在无耻的自我推销行为中,这是我早期研究的结果:
http://www.magentocommerce.com/boards/viewreply/211050/六年过去了,上面的链接已经失效了。而且我的 nginx 配置更加成熟。下面首先阻止所有文件并只允许那些明确公开的文件。所有其他请求都将重写到
index.php
。如果您想执行其他 PHP 文件,您必须编写自己的排除。这是我能想到的最安全的方法。/etc/nginx/magento_server:/etc/nginx/conf.d/php.conf
:
每个商店都有自己的服务器块,类似于:
/etc/nginx/sites-enabled/yoursite.com:
自从
.htaccess
文件被忽略(因为这不是 Apache),它有助于将.user.ini
放入每个 Web 根目录:/var/www/.user.ini
I have some experience with nginx in this regard and have even written about it. So in a shameless act of self-promotion here is the result of my earlier research:
http://www.magentocommerce.com/boards/viewreply/211050/Six years on and the above link is dead. Also my nginx configs are more mature. The following starts by blocking all files and only allowing those which are explicitly public. All other requests are rewritten to
index.php
. If you want to execute some other PHP file you must write your own exclusion. This is the safest way I can think of./etc/nginx/magento_server:
/etc/nginx/conf.d/php.conf:
Each store then has it's own server block similar to this:
/etc/nginx/sites-enabled/yoursite.com:
And since
.htaccess
files are ignored (because this is not Apache) it helps to put.user.ini
in each web root:/var/www/.user.ini
您可以尝试添加类似于此的重写规则
抱歉,它未经测试,但应该很接近。更多信息:
http://wiki.nginx.org/NginxHttpRewriteModule
You could try adding a rewrite rule similar to this
Sorry, it's untested, but it should be close. More info:
http://wiki.nginx.org/NginxHttpRewriteModule
我在上面的答案中看不到“/index.php/foo/bar”被永久重定向到“/foo/bar”的任何地方。经过一番努力消除无限重定向问题后,我决定使用以下初始配置来实现此目的:
其中 php.conf 包含标准 FastCGI 参数设置,例如:
I can't see anywhere in the answers above where "/index.php/foo/bar" was being redirected permanently to "/foo/bar". After a bit of mucking around to eliminate the infinite redirect problem, I've settled on the following initial config to achieve this:
where php.conf contains the standard FastCGI parameter setup, for example: