[英]Redirect users from page.php to page with nginx
I have the following server block: 我有以下服务器块:
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;
}
}
It already handles url rewriting (process petpal.co.il/dogs as dogs.php), however, I want to avoid people from reaching page.php so there won't be duplicated pages (same page named x and x.php), so all I want to do is adding a rule that will redirect people from page.php to page without .php OR at least showing a 404 not found page (what do you think is better?) 它已经可以处理url重写(将petpal.co.il/dogs作为dogs.php处理),但是,我想避免人们到达page.php,因此不会出现重复的页面(相同的页面分别名为x和x.php) ,所以我要做的就是添加一条规则,将人们从page.php重定向到没有.php的页面,或者至少显示未找到404的页面(您认为更好吗?)
Hope I explained it well, any clues? 希望我解释清楚,有什么线索吗? Thanks! 谢谢!
I'm not sure if I fully understand your question but instead of writing a rule you could do the following. 我不确定我是否完全理解您的问题,但您可以执行以下操作,而不是编写规则。
Now if you go to petpal.co.il/dogs it will show petpal.co.il/dogs/index.php. 现在,如果您转到petpal.co.il/dogs,它将显示petpal.co.il/dogs/index.php。
Users can still go to dogs/index.php but it isn't a duplicate page. 用户仍然可以访问dogs / index.php,但这不是重复的页面。
Hope it helps! 希望能帮助到你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.