
我真的很難理解並實作 nginx 中一個非常簡單的操作。
我正在嘗試重寫以下頁面:
http://test.domain.com/prova_pagina.php
到
http://test.domain.com/p/
我在 nginx.conf 中有以下內容:
server {
listen 82;
root /dir;
include /nginx/conf/mod_pagespeed.conf;
include /nginx/conf/expiry_directives.conf;
server_name test.domain.com;
index theindex.php;
location / {
rewrite ^/d/ /prova_pagina.php last;
}
location ~ \.php$ {
include /nginx/conf/fastcgi_params;
fastcgi_index theindex.php;
if (-f $request_filename) {
fastcgi_pass 127.0.0.1:9000;
}
}
}
它確實有效,但問題是所有外部連結(例如 css 和 js)都會在網域後面附加 /d/ 。
有什麼幫助嗎?有什麼簡單的教學可以讓我了解如何正確實現這一目標嗎?
謝謝你的幫忙。
答案1
試試這樣:
# serving normal pages
location / {
try_files $uri $uri/ /index.php?$args;
}
# the page to be redirected
location /prova_pagina.php {
rewrite ^ http://test.domain.com/p/;
}