dongwu3747 2015-08-03 08:16
浏览 59

将用户从page.php重定向到使用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?)

Hope I explained it well, any clues? Thanks!

  • 写回答

1条回答 默认 最新

  • doupan6648 2015-08-03 08:21
    关注

    I'm not sure if I fully understand your question but instead of writing a rule you could do the following.

    • Create a dogs folder
    • Create an index.php file inside it and edit that file

    Now if you go to petpal.co.il/dogs it will show petpal.co.il/dogs/index.php.

    Users can still go to dogs/index.php but it isn't a duplicate page.

    Hope it helps!

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题