具有seo友好文件名的nginx干净url [英] nginx clean url with seo friendly file names

查看:83
本文介绍了具有seo友好文件名的nginx干净url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望实现以下功能,这些功能可以在Apache下正常运行.这样做是为了获得更好的URL SEO.

I wish to implement the following which is working perfectly under Apache. This is being done for better SEO of the URLs.

示例网址:

http://www.astrogyan.com/enter/indian_astrology_horoscope_chart_prediction.html
http://www.astrogyan.com/know_your_gemstone/gID-7/sani_planet_saturn_gemstone_blue_sapphire_neelam.html

我真正期待的是一个位置正则表达式,它只能在ROOT FOLDER中捕获所有无扩展名的php脚本,以便由php-fptm进行处理.

What I am exactly looking forward to is a location regex to catch all extension-less php scripts in the ROOT FOLDER ONLY for processing by php-fptm.

在上述所有URL中,"enter","know_your_gemstone"都是PHP脚本,其后是PHP为SEO生成的虚拟文件名.实际上"indian_astrology_horoscope_chart_prediction.html"文件名不存在.在Apache中,我使用以下代码拦截"enter/know_your_gemstone"等代码,并且从不担心其余的文件名:

In all the above URLs "enter", "know_your_gemstone" are all PHP scripts and what follows them are dummy file names generated by PHP for SEO. Actually "indian_astrology_horoscope_chart_prediction.html" file name does not exist. In Apache, I use the following which intercepts "enter / know_your_gemstone" etc and never bothers about the rest of the file name:

DefaultType application/x-httpd-php

在上述URL的最后,"gID-7"用于将变量传递到脚本以显示适当的内容.当此URL显示动态内容时,该URL的设计是如此精致,以至于看起来像STATIC URL,可以被搜索引擎轻松索引.这个变量解析已经在PHP中完成,与Nginx无关.我相信这部分已经被称为漂亮的URL/干净的URL.

In the last of the above URL, "gID-7" is used to pass a variable to the script to show appropriate content. While this URL is showing DYNAMIC content, the URL is so crafted that is looks like a STATIC URL which can be indexed by search engines easily. This variable parsing is done in PHP already and has nothing to do with Nginx. I beleive this part is already referred as pretty url / clean url.

我需要知道在NGINX下如何最好地实现这一目标?我需要使用正则表达式来处理ROOT FOLDER中的所有脚本(扩展名较少的文件),而忽略此类脚本名称后面的内容.如果不存在这样的文件,则考虑检查URL的其余部分,希望它是一个有效的目录,后跟一个文件名.该目录部分是可选的,对于我目前的需求不是必需的.

I need to know how best can this be implemented under NGINX? I need the regex to process all scripts (extension less files) in ROOT FOLDER and ignore what follows after such script names. If such a file does not exist, then consider to check the rest of the URL hoping it to be a valid directory followed by a file name. This directory portion is optional and not essential to my present needs.

我有一个运行ubuntu的VPS,其中我已经用php-fpm安装了nginx,对于正常的URL,如index.htm/index.php,安装程序工作正常.我不是正则表达式编写方面的专家,因此在这个关键时刻我陷入了困境.我在许多nginx博客/论坛下在线搜索,但找不到正确的解决方案.

I have a VPS running ubuntu where I have installed nginx with php-fpm and for normal URL's like index.htm / index.php the setup is working fine. I am not a pro in regex writing hence I am stuck up at this juncture. I searched online under many nginx blogs / forum but could not find the right solution.

我正在将Nginx v1.1.17的最新开发版本与php v5.3.6.13一起使用.我还编译了其他模块,例如更多的标头,缓存清除,内存缓存等.

I am using the latest development version of Nginx v1.1.17 with php v5.3.6.13. I have also compiled additional modules like more header, cache purge, memcache etc.

对此将提供任何帮助,我们将不胜感激.预先感谢...

Any help on this will be most appreciated. Thanks in advance...

推荐答案

这应该对您有用:

server {
    listen 80;
    server_name example.com;
    root   /full/server/path/to/your/cms;
    index  index.php;

    location / {
        try_files $uri $uri/ /phphandler
    }

    location /phphandler {
        internal;
        # nested location to filter out static items not found
        location ~ .php$ {
            rewrite ^/([^/]*)(.*) /$1 break;
            fastcgi_pass   127.0.0.1:8080;
            ...
        }
    }
}

代理的替代方式:

server {
    listen 80;
    server_name example.com;
    root   /full/server/path/to/your/cms;
    index  index.php;

    location / {
        try_files $uri $uri/ /phphandler
    }

    location /phphandler {
        internal;
        # nested location to filter out static items not found
        location ~ .php$ {
            rewrite ^/([^/]*)(.*) /$1 break;
            proxy_pass   127.0.0.1:8080;
            ...
        }
    }
}

这篇关于具有seo友好文件名的nginx干净url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆