htaccess的URL重写与URL多个变量 [英] htaccess url rewrite with multiple variables in url

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

问题描述

我想在我的.htaccess文件做一些URL重写规则,使此链接: http://myseite.com/index.php?var1=value1&var2=value2 将变成: http://myseite.com/var1/value2.html

I want to make some url rewrite rules on my .htaccess file so that this link: http://myseite.com/index.php?var1=value1&var2=value2 will become : http://myseite.com/var1/value2.html

到目前为止,我已经设法成功地解决了这个问题,但只为一个变量。

So far I have managed successfully to solve this problem but only for one variable.

我也试过这个code:

I also tried this code:

RewriteRule ^([^/]*)/([^/]*)\.html$ /index.php?var1=$1&var2=$2 [L]

不过,这是行不通的。

But it doesn't work..

感谢您的帮助!

推荐答案

请求 http://mysite.com/var1/value2.html 改写为 http://mysite.com/index.php?var1=var1&var2=var2

在这里的index.php和.htaccess文件是在的DocumentRoot

where index.php and .htaccess file are at the documentroot

如果httpd.conf文件(或某些阿帕奇的conf文件)已设置AllowOverride全部设置为你工作在DocumentRoot的.htaccess文件将只工作,检查第一。

.htaccess files will only work if httpd.conf (or some apache conf file) has "AllowOverride All" set for the DocumentRoot you are working in. Check that first.

接下来,请确保您有mod_rewrite的Apache中conf文件使能(重启Web服务器不断变化的conf文件后),然后启用它在你的.htaccess文件

Next, make sure you have mod_rewrite enabled in Apache conf files (restart webserver after changing conf files) and then enable it in your .htaccess file

的.htaccess的内容:

contents of .htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
# /var1/value2.html to /index.php?var1=value1&var2=value2
RewriteRule ^([^/]+)/([^\.]+)\.html$ /index.php?var1=$1&var2=$2
</IfModule>

把这个的index.php看到它的工作:

put this in /index.php to see it work:

<? print_r($_GET); ?>

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

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