duanbei3704 2011-04-14 08:08
浏览 15
已采纳

Mod_rewrite扁平链接

I'm trying to display my get variables as flat links. Want to change from this:

http://mydomain.com/index.php?page=shop&var1=hat&var2=10

to

http://mydomain.com/index.php/shop/hat/10

Please keep in mind that there isn't a fixed number of variables, that's why I use var1,var2,...etc

[edit] I already have a partially working script, but works only with max 3 variables

RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
RewriteRule ^([^/\.]+)/?([^/\.]+)/?$ index.php?page=$1&var=$2 [L]
RewriteRule ^([^/\.]+)/?([^/\.]+)/?([^/\.]+)/?$ index.php?page=$1&var=$2&var2=$3 [L]
RewriteRule ^([^/\.]+)/?([^/\.]+)/?([^/\.]+)/?$ index.php?page=$1&var=$2&var2=$3&var3=$4 [L]
  • 写回答

2条回答 默认 最新

  • duanpo8329 2011-04-14 09:22
    关注

    So first remember mod_rewrite works like this :

    http://mydomain.com/index.php/shop/hat/10
    

    (what the client type) is rewritten to

    http://mydomain.com/index.php?page=shop&var1=hat&var2=10
    

    (what the client is served), but not necessarily displayed like the latter. (Unless you make it a redirect)

    So assuming your format is completly described here :

    RewriteRule ^index\.php/([^/]+)/([^/]+)/([0-9]+)$ /index.php?page=$1&var2=$2&var2=$3
    

    Should be good.

    EDIT:

    Oh BTW! I did not take the variable number of variable into account. That should not be processed by mod_rewrite I think. Maybe the best shot is to RewriteRule index.php/(.*) /index.php?call=$1 and then use your script to explode using / delimiter.

    You can only do it if you already know the number of variable only AFAIK.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图