用于SEO友好URL结构的Nginx重写规则-WordPress和另一个Web应用程序 [英] Nginx rewrite rules for SEO friendly URL structure - WordPress and another Web application
问题描述
我已经在我的根example.com/网站上安装了WordPress.
I have got WordPress installed on my root example.com/ Website.
此外,我在example.com/my-app/上还有另一个Web应用程序,该应用程序具有丑陋的链接,例如example.com/my-app/file.php?arg=value可以访问.
Also I have another Web application that on example.com/my-app/ which has got ugly links like example.com/my-app/file.php?arg=value to access.
如何使我的应用程序SEO友好URI结构像下面的示例所示?
How can I make my-app SEO friendly URI structure working as example below?:
example.com/my-app/file.php?arg=value
to
example.com/my-app/value/
当前,如果我访问example.com/my-app/value/,它将重定向到我的WordPress帖子,其中包含/value/的某些字符.为什么?反正有什么办法让它正常工作?
Currently, if I access to example.com/my-app/value/ it redirects me to my WordPress post which contains some characters of the /value/. Why? Is there anyway to get this working?
我的domain Nginx指令如下:
My Nginx directives for domain are listed below:
location / {
try_files $uri $uri/ /index.php?$args;
fastcgi_read_timeout 300;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
有什么想法吗?我应该在开关盒中使用Ajax导航吗?HTML5 pushState()API呢?有可行的例子吗?
Any ideas? Should I use Ajax navigation, with switch cases? What about HTML5 pushState() API? Any working examples?
感谢帮助!
推荐答案
WordPress和 my-app
都在一个通用文档根目录下工作,这使事情变得简单.
Both WordPress and my-app
work within a common document root which makes things simple.
try_files 指令的最后一个元素是(例如)SEO友好URL的默认操作.
The last element of the try_files
directive is the default action for (for example) SEO friendly URLs.
您需要使用以/my-app
开头的URI的其他默认处理程序,例如,可以使用 location/my-app
块来实现:>
You need a different default handler for URIs which begin with /my-app
, which is achieved using a location /my-app
block, for example:
location / {
try_files $uri $uri/ /index.php?$args;
}
location /my-app {
try_files $uri $uri/ /my-app/file.php?arg=$uri&$args;
}
location ~ \.php$ {
try_files $uri =404;
...
}
在上述情况下,将 arg
设置为值/my-app/value
.如果确实必须提取URI的最后一部分,请添加带有重写的命名位置,例如:
In the above case, arg
is set to the value /my-app/value
. If you really must extract the last part of the URI, add a named location with a rewrite, for example:
location / {
try_files $uri $uri/ /index.php?$args;
}
location /my-app {
try_files $uri $uri/ @rewrite;
}
location @rewrite {
rewrite ^/my-app/(.*)$ /my-app/file.php?arg=$1;
}
location ~ \.php$ {
try_files $uri =404;
...
}
请注意,您需要将 fastcgi_read_timeout 300;
(在您的问题中)放置在 location〜\ .php $
块或外部块之一中,为了有效.
Note that the fastcgi_read_timeout 300;
(in your question) needs to be placed in the location ~ \.php$
block, or in one of the outer blocks, in order to be effective.
有关使用 nginx
指令的详细信息,请参见此以上.
See this for details of the nginx
directives used above.
这篇关于用于SEO友好URL结构的Nginx重写规则-WordPress和另一个Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!