什麼,我想實現的一個例子,我想重寫mod_rewrite的動態URL
www.website.com/index.php
www.website.com
和
www.website.com/index.php?page=first
www.website.com/first
而且
www.website.com/index.php?category=cat &頁=第二
www.website.com/cat/second
非常感謝
什麼,我想實現的一個例子,我想重寫mod_rewrite的動態URL
www.website.com/index.php
www.website.com
和
www.website.com/index.php?page=first
www.website.com/first
而且
www.website.com/index.php?category=cat &頁=第二
www.website.com/cat/second
非常感謝
嘗試這樣的事情
<IfModule mod_rewrite.c>
RewriteEngine On
# you may want to check other uses of R
RewriteRule ^/index.php$/[R=301,L]
RewriteRule ^/index.php?page=(.*) /$1 [R=301,L]
RewriteRule ^/index.php?category=(.*)&page=(.*) /$1/$2 [R=301,L]
</IfModule>
您可能可以將最後兩行放在一行中,播放正則表達式。 另外,請參閱this question,您可能需要查看ServerFault以獲取更多信息。 許多問題都是這樣的。
您是否100%確定您要重寫這種方式嗎?這似乎是通常設置重寫的倒退。看看this question和first answer看看我的意思。
我要去無路可退,並要求也許你想在瀏覽器中樣子的URL :
http://www.website.com/cat/second
以及您希望您的PHP應用程序到再收到:
http://www.website.com/index.php?category=cat&page=second
在這種情況下,你會想要像
<IfModule mod_rewrite.c>
RewriteEngine On
# note this first rewrite would be redundant in 99.999% of cases, apache expects to serve index.php for the/
RewriteRule ^/$ /index.php [last]
RewriteRule ^(.*)$ /index.php?page=$1 [last]
RewriteRule ^(.*)/(.*)$ /index.php?category=$1&page=$2 [nocase,last]
</IfModule>
如果我錯了,那麼Ivan c00kiemon5ter V卡納克的答案會做你的權利。然後我也很好奇你在什麼樣的情況下想要做「反改寫」:)
我喜歡你的方法比我的更好。 +1從我 沒有想到它,這樣:)謝謝 – c00kiemon5ter 2011-06-07 20:43:07
@Ivan c00kiemon5ter - 嘿謝謝。我很好奇@ user782958會告訴我們他們正在努力實現的目標。 – 2011-06-09 13:19:34