Apache的mod_rewrite一个任意数量的可能性规则 [英] apache mod_rewrite one rule for any number of possibilities

查看:139
本文介绍了Apache的mod_rewrite一个任意数量的可能性规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建一个相当大的网站,我的.htaccess开始感觉到有点臃肿,有没有取代我当前系统的一种方式 - 一个规则为每一个可以通过增值分销商的数量不可能性,为一个陷阱所有前pression能占到不同的输入数字?

I'm building a fairly large website and my .htaccess is starting to feel a bit bloated, is there a way of replacing my current system of - one rule for each of the possibile number of vars that could be passed, to one catch all expression that can account for varying numbers of inputs ?

例如我目前有

RewriteRule ^([a-z]+)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)$ /index.php?mode=$1&id=$2&$3=$4&$5=$6
RewriteRule ^([a-z]+)/([^/]*)/([^/]*)/([^/]*)$ /index.php?mode=$1&id=$2&$3=$4
RewriteRule ^([a-z]+)/([^/]*)$ /index.php?mode=$1&id=$2
RewriteRule ^([a-z]+)$ /index.php?mode=$1

第一反向引用总是模式和(如有更多存在)第二总是 ID 的,此后输入的名称和之间的任何进一步向引用备用其值

the first backreference is always the mode and (if any more exist) the second is always id, thereafter any further backreferences alternate between the name of the input and its value

http://www.domain.com/search
http://www.domain.com/search/3039/sort_by/name_asc/page/23

我很想能够有一个前pression优雅地处理所有的输入。

i would love to be able to have one expression to gracefully handle all the inputs.

感谢

推荐答案

不喜欢Drupal的:

Do like Drupal:

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

,然后使用PHP的code这样的事情处理所有的东西在你的脚本

And then handle all the stuff in your script using php code something like this

$pathmap = ();
if ($_GET["q"]){
    $path = split("/", $_GET["q"]);
    for ($i=0; $i+1<count($path); $i++){
        $pathmap[$path[$i]] = $path[$i+1];
        $i++;
    }
}

这篇关于Apache的mod_rewrite一个任意数量的可能性规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆