【发布时间】:2015-10-25 06:37:41
【问题描述】:
我有以下服务器块:
server {
listen 80;
server_name petpal.co.il;
root /usr/share/nginx/petpal;
index index.php;
rewrite ^/([a-zA-Z]+)\-([0-9\-]+)$ /$1.php?page=$2? last;
rewrite ^/en/([a-zA-Z]+)\-([0-9\-]+)$ /en/$1.php?page=$2? last;
location / {
try_files $uri $uri/ @extensionless-php;
}
location @extensionless-php {
rewrite ^(.*)$ $1.php last;
}
set $lang "";
if ($uri ~ "^/en/") {set $lang "en/";}
error_page 404 /${lang}notfound;
location ~ \.php$ {
try_files $uri =404;
client_max_body_size 4M;
fastcgi_read_timeout 300;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
它已经处理了 url 重写(将 petpal.co.il/dogs 处理为 dogs.php),但是,我想避免人们访问 page.php,因此不会有重复的页面(名为 x 和 x 的同一页面.php),所以我要做的就是添加一个规则,将人们从 page.php 重定向到没有 .php 的页面,或者至少显示一个 404 not found 页面(你认为什么更好?)
希望我解释得很好,有什么线索吗? 谢谢!
【问题讨论】:
标签: php nginx url-rewriting