htaccess的URL重写URL

问题描述:

我要让我的.htaccess文件的一些URL重写规则,使这个链接:http://myseite.com/index.php?var1=value1&var2=value2将变为:http://myseite.com/var1/value2.htmlhtaccess的URL重写URL

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

我也试过这个代码:

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

但它不工作..

感谢您的帮助!

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

其中的index.php和.htaccess文件是在DocumentRoot的

.htaccess文件将只工作,如果httpd.conf文件(或一些阿帕奇的conf文件)为您正在使用的DocumentRoot设置了“AllowOverride All”。首先检查。

接下来,确保你在Apache的conf文件使能(重启Web服务器改变conf文件后)的mod_rewrite,然后启用它在你的.htaccess文件的.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看到它的工作:

<? print_r($_GET); ?> 
+1

它不工作:(,我已经试过了丑陋的链接,只有那些工作..如果我尝试值1/value2.html这是行不通的它说网页不是基金会d – Cata 2011-02-08 07:43:11