當前位置: 首頁 >> web 技術 >> zBlogPHP 如何在Nginx,捕抓過期舊網址,跳轉301 >> 正文

zBlogPHP 如何在Nginx,捕抓過期舊網址,跳轉301

2017-12-30     分類:web 技術     閱讀次數:1771     評論(0)    

為了因應SEO,或者是轉換zBlogASP至zBlogPHP,總有一些偽靜態的網址不再適用。就是在IIS環境的zBlogASP,轉換成NGINX的zBlogPHP中,所發現的問題方生本文。


例如,我在IIS環境的zBlogASP的過期舊網址為:

http://blog.hiastro.com.tw/2015/webtechs/iis-URL-Rewrite-space-resolve/1234.html


NGINX中,捕抓過期舊網址,跳轉301的作法,則是在nginx.conf 的 location / {} 內,新增指令如下:

rewrite ^\/\d+\/(.+)\/(.+)\/\d+\.html$ /$1/$2 permanent;

轉換跳轉301結果為

http://blog.hiastro.com.tw/webtechs/iis-URL-Rewrite-space-resolve


依舊正常偽靜態中


以下是zBlog偽靜態在NGINX設定範例

        #provide by zblog
        rewrite ^\/\d+\/(.+)\/(.+)\/\d+\.html$ /$1/$2 permanent;
        if (-f $request_filename/index.html){
            rewrite (.*) $1/index.html break;
        }
        if (-f $request_filename/index.php){
            rewrite (.*) $1/index.php;
        }
        if (!-f $request_filename){
            rewrite (.*) /index.php;
        }


轉載請註明出處為「本文轉載於『油拉林』原地址: http://blog.hiastro.com.tw/webtechs/zblogphp-nginx-rewrite-301

評論

發表評論   

暱稱*

E-mail*(建議輸入,以便收到博主回復的提示郵件)

網站

驗證碼*