2012-01-23 148 views

回答

5

我发现这篇文章在这个问题上有所帮助:clean urls in nginx

向下滚动到“画龙点睛 - 海基会的URL”部分,看看它是如何轻松完成。

干杯。

+0

谢谢,文章是有用 – Joel

+0

谢谢,有同样的问题 –

2

总之,您需要让NGINX知道如果该文件不存在,不会抛出404错误,而是请拨打index.php。 Wordpress足够聪明,可以将URL解析为参数,并提供正确的页面。

加入这个片段在你服务器的配置块:

location/{ 
    try_files $uri $uri/ /index.php?$args; 
} 

这里是nginx.org一个完整的例子:

# Upstream to abstract backend connection(s) for php 
upstream php { 
     server unix:/tmp/php-cgi.socket; 
     server 127.0.0.1:9000; 
} 

server { 
     ## Your website name goes here. 
     server_name domain.tld; 
     ## Your only path reference. 
     root /var/www/wordpress; 
     ## This should be in your http block and if it is, it's not needed here. 
     index index.php; 

     location = /favicon.ico { 
       log_not_found off; 
       access_log off; 
     } 

     location = /robots.txt { 
       allow all; 
       log_not_found off; 
       access_log off; 
     } 

     location/{ 
       # This is cool because no php is touched for static content. 
       # include the "?$args" part so non-default permalinks doesn't break when using query string 
       try_files $uri $uri/ /index.php?$args; 
     } 

     location ~ \.php$ { 
       #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini 
       include fastcgi.conf; 
       fastcgi_intercept_errors on; 
       fastcgi_pass php; 
     } 

     location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { 
       expires max; 
       log_not_found off; 
     } 
} 
+0

注意“非默认永久链接”也包括类别链接。在我的初始设置中,这行读取'try_files $ uri $ uri/= 404';用'/index.php?$ args'替换'= 404'是让我的分类链接重新运行的必要步骤。 – rsfinn