2009-06-25 18 views
0

因此改寫了我的醜PHP網址的東西更漂亮:強制美化URL用mod_rewrite的

RewriteEngine On 
RewriteRule ^main/photo([^/\.]+)/?.html$ main/details.php?gid=$2pid=$1 

不過,現在我想強迫任何人誰去

http://www.example.com/main/details.php?gid=20&pid=5 

重定向到

htto://www.example.com/main/photo5.html 

我試過以下RewriteCond:

RewriteCond %{REQUEST_URI} ^/main/details\.php [NC] 
RewriteRule ^main/details.php?gid=(.*)&pid=(.*) http://www.example.com/main/photo$1.html [R=301,L] 

但這並沒有奏效。有任何想法嗎?

回答

0

您需要查看request line以確定當前請求URI是否是原始請求。此外,您需要使用RewriteCond指令來測試URI的查詢:

RewriteCond %{THE_REQUEST} ^GET\ /main/details\.php 
RewriteCond %{QUERY_STRING} ^(([^&]*&)*)pid=([0-9]+)(&.*)?$ 
RewriteRule ^main/details\.php$ /main/photo%3.html? [L,R=301] 
+0

我得到發送到photo.html?pid = 5。 – 2009-06-25 16:05:25