2011-02-08 170 views
0

我要讓我的.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] 

但它不工作..

感謝您的幫助!

回答

4

申請 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