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 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱