dpg76975 2016-08-31 12:25
浏览 56
已采纳

从example.com/script.php?param=value到example.com/value的Nginx重写

I have a PHP script that accepts a single parameter.

My project structure is like the following:

index.php
i.php
terms.php
functions
includes
icons
resources

The script that I want to rewrite its URL is i.php from

example.com/i.php?icon=id

to

example.com/id

While making sure everything else is normally accessible (e.g. example.com/terms.php).

How do I do that?

Edit This might be helpful. Here's my previous .htaccess that I used to use on my apache server:

Options +FollowSymLinks  
RewriteEngine On  

RewriteCond %{SCRIPT_FILENAME} !-d  
RewriteCond %{SCRIPT_FILENAME} !-f  
RewriteRule ^(\w+)$ ./i.php?icon=$1
  • 写回答

2条回答 默认 最新

  • dongmin4990 2016-08-31 20:39
    关注

    I've got it working by using this:

    location / {
        try_files $uri $uri/ /i.php?icon=$uri;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 全书网Java爬取数据
  • ¥15 SAP HANA SQL Script 。SUM OVER 怎么加where
  • ¥15 怎么获取红包封面的原始链接,并且获取红包封面序列号
  • ¥100 微信小程序跑脚本授权的问题
  • ¥60 为什么使用python对地震数据进行umap降维后,数据成图会出现不连续的现象
  • ¥100 房产抖音小程序苹果搜不到安卓可以付费悬赏
  • ¥15 STM32串口接收问题
  • ¥15 腾讯IOA系统怎么在文件夹里修改办公网络的连接
  • ¥15 filenotfounderror:文件是存在的,权限也给了,但还一直报错
  • ¥15 MATLAB和mosek的求解问题