Nginx 重新導向 偽靜態 rewrite index.php

來源:互聯網
上載者:User

標籤:base   基礎上   是的   details   views   檔案   偽靜態   thinkphp   proxy   

參考https://www.kancloud.cn/manual/thinkphp5/177576

thinkphp入口檔案同目錄下添加。把下面的內容儲存為.htaccess檔案

 

<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]
</IfModule>

 

 

 

伺服器 

vim  /usr/local/nginx/conf/vhost/www.phpaaa.com.conf

在http{ server{  }}裡寫代碼,在原來那些location附近寫

 

   location / {

                if (!-e $request_filename){

                        rewrite ^/(.*)$ /index.php/$1 last;

                 }

        }

 

 

重啟

lnmp start

 

 

使用情境:我想輸入www.abc.com/a/1後,實際上是跳轉到www.abc.com/index.PHP/a/1


配置Nginx.conf在你的虛擬機器主機下添加:
location / {
     if (!-e $request_filename){
          rewrite ^/(.*)$ /index.php/$1 last;
     }
}


如果你的項目入口檔案在一個子目錄內,則:
location /目錄/ {
     if (!-e $request_filename){
          rewrite ^/目錄/(.*)$ /目錄/index.php/$1 last;
     }
}

 

 

Nginx主配置(預設虛擬機器主機)檔案:/usr/local/nginx/conf/nginx.conf

添加的虛擬機器主機設定檔:/usr/local/nginx/conf/vhost/網域名稱.conf

 

http://blog.csdn.net/beyondlpf/article/details/8261657

 

http://www.cnblogs.com/300js/p/6484642.html

 

 仔細觀察 rewrite ^(.*)/t(\d+)\.html$ $1/index.php?t=3 last;其實感覺nginx的偽靜態規則蠻好寫的。就是用正則的基礎上,一個rewrite來聲明,然後^是偽靜態規則開頭,(.*)匹配任一字元,這裡匹配的就是網域名稱了,t就是你在這裡想加的字元,如你可以加apple、orange這樣的分類名了,(\d+)匹配的是數字,\.html匹配的是尾碼,$就是正則匹配的結束。後面半部分就是要改寫的url了,用$1打頭,表示網域名稱,/index.php?t=3就是要改寫的URL,用last;結束即可。

來源: http://www.cnblogs.com/thinksasa/archive/2012/12/16/2820130.html

 

 rewrite ^(.*)/t(\d+)\.html$ $1/index.php?t=3 last;

 rewrite    輸入的url                 要跳轉的url   last;

==========================

(-d $request_filename)它有個條件是必需為真實目錄,而我的rewrite不是的,所以沒有效果

if (-d $request_filename){

rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;

}

=====================

檔案和目錄不存在的時候重新導向:

複製代碼代碼如下:

 

if (!-e $request_filename) {

proxy_pass http://127.0.0.1;

}

=====

Nginx 重新導向 偽靜態 rewrite index.php

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.