dongmo9996 2017-12-20 09:58
浏览 16

删除部分URI,然后传递给脚本

Currently my .htaccess looks like this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [QSA]

All URIs are passed to the PHP script which then parses it and returns stuff.

Now I want to implement a versioning system, in which there would be different script handling the URIs depending on the version called.

That is:

  • if I call /v1/countries/es/users, I want to pass the URI /countries/es/users to the script v1.php
  • if I call /v2/users/314/settings, then I want the URI /users/314/settings passed to the script v2.php

I tried doing something like

RewriteRule ^/?v(\d)/.*$ v$1.php [QSA]

That would send execution to the version-specific script, but I still want to strip out the /v1/ initial part of the URI when passed to the script, i.e., I want the script to receive the URI without the initial version part. How can I achieve that?

  • 写回答

1条回答 默认 最新

  • dqfkd82886 2017-12-20 13:27
    关注

    It clearly explains in apache document: Apache mod_rewrite Introduction.

    You could pass it as parameter, and use $_GET['route'] to get the URI part without first version part:

    RewriteRule ^/v(\d)/(.*)$ v$1.php?param1=$2 [QSA,L]
    RewriteRule ^/v(\d)/(.*)/(.*)$ v$1.php?param1=$2&param2=$3 [QSA,L]
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?