重写所有URL [英] Rewrite for all URLs

查看:104
本文介绍了重写所有URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重写是这样的:

访问http // www.example.com / index.php文件VAR1 = VAL1&放大器; VAR2 = val2的&安培; VAR3 = VAL3

进入

http://www.example.com/var1/val1/var2/val2/var3/val3/

我正在寻找一个解决方案,对变量的任意数量的工作。能不能做到?

I'm looking for a solution to work on an arbitrary number of variables. Can it be done?

推荐答案

看看这个问题:<一href=\"http://stackoverflow.com/questions/884377/can-modrewrite-convert-any-number-of-parameters-with-any-names\">Can mod_rewrite的转换任何数量的参数与任何名字?

<一个href=\"http://stackoverflow.com/questions/884377/can-modrewrite-convert-any-number-of-parameters-with-any-names\">My答案可以在你的情况下使用过:

My answer can be used in your case too:

$_SERVER['REQUEST_URI_PATH'] = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$segments = explode('/', trim($_SERVER['REQUEST_URI_PATH'], '/'));
for ($i=0, $n=count($segments); $i<$n; $i+=2) {
    $_GET[rawurldecode($segments[$i])] = ($i+1 < $length) ? rawurldecode($segments[$i+1]) : null;
}

和相应的规则是:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

本规则重写任何请求,这是不能被映射到一个现有的文件或目录,到的index.php

This rule rewrites any request, that can not be mapped to an existing file or directory, to the index.php.

这篇关于重写所有URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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