導航:首頁 > 編程語言 > phpnginx偽靜態

phpnginx偽靜態

發布時間:2022-07-01 22:11:37

Ⅰ 如何寫nginx偽靜態規則

location / {

rewrite wx-hot-id-88.html index.php?m=wx&a=hot&id=88 break;
}
你這種是固定,比如說其中有不固定的就這樣寫
rewrite ([a-z]{2})-hot-id-([0-9]+).html index.php?m=$1&a=hot&id=$2 break;
為靜態的作用就是讓網路收錄你的網站的時候的URL是html樣式,但是當用戶通過網路訪問過來的時候 ,自動跳轉到正常的網站地址。

Ⅱ 如何配置nginx偽靜態以支持ThinkPHP的PATHINFO模式

打開Nginx的配置文件 /usr/local/nginx/conf/nginx.conf
一般是在這個路徑,根據你的安裝路徑可能有所變化。如果你配置了vhost,而且只需要你這一個vhost支持pathinfo的話,可以直接打開你的
vhost的配置文件。找到類似如下代碼(不同版本的nginx可能稍有不同,但是相差不會很遠):

location~.*.(php|php5)?$
{
#原有代碼
}

修改成以下代碼:

#去掉$是為了不匹配行末,即可以匹配.php/,以實現pathinfo
#如果你不需要用到php5後綴,也可以將其去掉
location~.php
{
#原有代碼

#定義變數$path_info,用於存放pathinfo信息
set$path_info"";
#定義變數$real_script_name,用於存放真實地址
set$real_script_name$fastcgi_script_name;
#如果地址與引號內的正則表達式匹配
if($fastcgi_script_name~"^(.+?.php)(/.+)$"){
#將文件地址賦值給變數$real_script_name
set$real_script_name$1;
#將文件地址後的參數賦值給變數$path_info
set$path_info$2;
}
#配置fastcgi的一些參數
fastcgi_paramSCRIPT_FILENAME$document_root$real_script_name;
fastcgi_paramSCRIPT_NAME$real_script_name;
fastcgi_paramPATH_INFO$path_info;
}

這樣,nginx伺服器就可以支持pathinfo了。但是如果要支持ThinkPHP的URL_MODE設置為2的模式,還需要配置rewrite規則。找到access_log語句,在其上方加上以下語句:

#如果請求既不是一個文件,也不是一個目錄,則執行一下重寫規則
if(!-e$request_filename)
{
#地址作為將參數rewrite到index.php上。
rewrite^/(.*)$/index.php/$1;
#若是子目錄則使用下面這句,將subdir改成目錄名稱即可。
#rewrite^/subdir/(.*)$/subdir/index.php/$1;
}

Ⅲ Nginx偽靜態php設置方法

修改/etc/nginx/nginx.conf,tae的話可能在conf.d里邊的virtual.conf,在server里邊添加偽靜態規則

python">location/{
indexindex.phpindex.htmlindex.htm;
rewrite^(.*)/item/([0-9]+).html$1/item.php?id=$2last;
}

大概是這樣,規則要自己測試

Ⅳ phpcms偽靜態在nginx怎麼寫

location / {
###以下為PHPCMS 偽靜態化rewrite規則
rewrite ^(.*)show-([0-9]+)-([0-9]+)\.html$ $1/show.php?itemid=$2&page=$3;
rewrite ^(.*)list-([0-9]+)-([0-9]+)\.html$ $1/list.php?catid=$2&page=$3;
rewrite ^(.*)show-([0-9]+)\.html$ $1/show.php?specialid=$2;
####以下為PHPWind 偽靜態化rewrite規則
rewrite ^(.*)-htm-(.*)$ $1.php?$2 last;
rewrite ^(.*)/simple/([a-z0-9\_]+\.html)$ $1/simple/index.php?$2 last;
}

Ⅳ thinkphp 偽靜態 nginx 規則怎麼設置

server {

listen 80;

server_name localhost;

index index.html index.htm index.php;

root /alidata/www/;


location / {

if (!-e $request_filename){

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

}

}


location ~ .*.(php|php5)?$

{

#fastcgi_pass unix:/tmp/php-cgi.sock;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

include fastcgi.conf;


# 以下是為了讓Nginx支持PATH_INFO

set $path_info "";

set $real_script_name $fastcgi_script_name;

if ($fastcgi_script_name ~ "^(.+?.php)(/.+)$") {

set $real_script_name $1;

set $path_info $2;

}

fastcgi_param script_FILENAME $document_root$real_script_name;

fastcgi_param script_NAME $real_script_name;

fastcgi_param PATH_INFO $path_info;


fastcgi_connect_timeout 120;

fastcgi_send_timeout 120;

fastcgi_read_timeout 120;

fastcgi_buffers 8 128K;

fastcgi_buffer_size 128K;


}

location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$

{

expires 30d;

}

location ~ .*.(js|css)?$

{

expires 1h;

}

#偽靜態規則

access_log /alidata/log/nginx/access/default.log;

}

Ⅵ 如何實現網站的偽靜態,分別說一下nginx和apache的實現方式

Nginx下設置偽靜態方法與Apache差不多,直接在nginx.conf (或者在對應的*.conf) 中找到需設置偽靜態規則的伺服器對應欄位,在server{ location/{ } }中添加以下代碼:

server{
listen80default_server;
server_name_;
location/{
root/usr/share/nginx/html;
indexindex.htmlindex.htm;
rewrite^(.*)list-([0-9]+)-([0-9]+).html$$1list.php?page=$2&id=$3;
}
}


添加後重啟Nginx服務即可生效


apache

要使用httpd.conf文件來設置偽靜態策略,我們可以直接在httpd.conf中寫入如下代碼,如果您的網站是配置在VirtualHost中,則將這段代碼加到對應的<VirtualHost hostname>

<VirtualHost>
標簽內:
<IfMolemod_rewrite.c>
#輸入:list-123-456.html
#輸出:list.php?page=123&id=456
RewriteEngineon
RewriteRule^(.*)list-([0-9]+)-([0-9]+).html$$1list.php?page=$1&id=$2
</IfMole>


添加完成後重啟httpd服務後即可生效

Ⅶ Nginx偽靜態規則怎麼設置

1、輸入以下命令
cd
/alidata/server/nginx/conf/rewrite再輸入ll
看看是不是像下面截圖的一樣。
2、這些就是偽靜態規則文件。我們打開phpwind.conf看看。
已經在rewrtie目錄下配置了常見程序的偽靜態規則。可以直接調用。
3、如果沒有就按照程序名.conf的命名方式新建一個配置文件
配置文件搞清楚了,你可能會說好像網站偽靜態還是沒效果啊。別著急,因為偽靜態規則是需要被網站配置文件調用才行的。
4、輸入以下命令
cd
/alidata/server/nginx/conf/vhosts
進入到網站配置目錄
5、打開配置文件
修改好偽靜態調用文件
下面測試下我們配置的文件是否正確吧輸入
nginx:
the
configuration
file
/alidata/server/nginx/conf/nginx.conf
syntax
is
ok
nginx:
configuration
file
/alidata/server/nginx/conf/nginx.conf
test
is
successful
如果出現以上兩句話就說明配置成功了。下面重啟下nginx就可以了。

Ⅷ phpStudy中nginx建DZ2.5怎麼設置偽靜態怎麼都不成功

關於偽靜態技術,最初是動態語言出現後為了解決用戶訪問的便利性和搜索蜘蛛的友好性。關於偽靜態的組件有ISAPI_Rewrite、開源的IIRF等。但ISAPI_Rewrite Lite版只支持全局的httpd.conf的,不支持分布式的httpd.ini的,只有收費的Full版才支持分布式httpd.ini。現在我們知道,Nginx也能實現簡單的偽靜態。更多介紹偽靜態可以參考

CI在Apache、Nginx上運行需要.htaccess配置文件,在IIS伺服器上則需要web.config文件,CI的偽靜態我們可以通過.htaccess裡面的規則設定
RewriteEngine on
RewriteCond $1 !^(index\\.php|system\\.php|images|skin|js|ls|swfupload|attachment|application|robots\\.txt)
RewriteRule ^(.*)$ /fx/index.php/$1 [L]
註: RewriteRule ^(.*)$ /webdir/index.php/$1 [L]里的webdir是你的CI程序目錄

Ⅸ nginx 的偽靜態的寫法

url是什麼都是可以的,關鍵的是在nginx的配置中,把原url rewrite成為真正的url。

比如有一個location是這樣配置的:

location/{
rootxxxx;
indexindex.php;
fastcgi_passxxx;
includefastcgi.conf;

//跳轉規則
rewrite"^/t/index.php/([^?]+)/([^?]+)"/t/$1/$2break;
}

一般而言,在訪問的url中不要暴漏一些部署的信息,因此,一個url完全可以用/Newsindex/index來訪問,只需要在rewriet的時候,能夠把這個url轉給合適的php腳本去處理就可以了。

rewrite"/Newsindex/index"/t/Newsindex/indexbreak;

這樣也能實現要求。

Ⅹ nginx偽靜態規則

在nginx中,rewrite的規則一般是:

rewritepatternreplacement[flag];

1. 其中pattern是匹配製定的url,這里採用pcre的正則表達式的匹配規則來進行;

2. replacement表示把匹配到的pattern的url轉發到replace表示的url;

nginx默認是會把原url的參數原封不動的掛在新url之後。如果想忽略參數,可以採用replacement?的形式。

3. flag主要包括break;last;permenant;等。

如問題,如果你的靜態url為

/forumstatic?mod=.....
可以採用如下的規則:
rewrite"/^+forumstatic"/document_root/forum.phpbreak;
或者重寫參數:只保留mod參數,並且把mod參數轉成m參數
rewrite"/^+forumstatic"/document_root/forum.php?m=$arg_mod?break;
閱讀全文

與phpnginx偽靜態相關的資料

熱點內容
注冊伺服器地址指什麼 瀏覽:431
文本命令行 瀏覽:95
撲克牌睡眠解壓 瀏覽:190
rc4演算法流程圖 瀏覽:157
胡蘿卜解壓方法 瀏覽:35
掃描pdf格式軟體 瀏覽:876
程序員在銀行開賬戶 瀏覽:516
android資料庫下載 瀏覽:749
中午伺服器崩潰怎麼辦 瀏覽:425
產品經理和程序員待遇 瀏覽:442
解憂程序員免費閱讀 瀏覽:109
錄像免壓縮 瀏覽:508
總結所學過的簡便演算法 瀏覽:362
南昌哪些地方需要程序員 瀏覽:761
三台伺服器配置IP地址 瀏覽:175
如何用命令方塊連續對話 瀏覽:280
win7linux共享文件夾 瀏覽:304
命令符打開本地服務 瀏覽:601
android應用程序源碼 瀏覽:705
安卓開發工程師簡歷怎麼寫 瀏覽:63