2010-06-09 101 views
2

我目前正在重寫URL重寫URL從與mod_rewrite的

http://domain.com/profile/?u=10000017564881 

這本

http://domain.com/profile/10000017564881 

與以下重寫

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*?)\/?$ index.php?u=$1 [L] 

不過,我想,以優化seo litte and go with:

http://domain.com/profile/10000017564881/Anything-I-want-here 

顯然/任何事情,我想學這裏只是空忽略...

任何想法的傢伙? 非常感謝

回答

6

只需從正則表達式中刪除$,任何ID號後的內容都將被忽略,並且URL將被正確地重寫。

RewriteRule ^(.*?)\/? index.php?u=$1 [L] 

# the following will work the same (as far as I can tell), and 
# it's a lot more obvious at first glance what it does, which is 
# match everything until the first slash 
RewriteRule ^([^/]+)  ... 

當我做這樣的事情,我想驗證碼網址,301重定向,如果「任何事情,我想學這裏的」不匹配的數據。

+0

RewriteRule ^([^ /])\ /? index.php?u = $ 1 [L] 是否這樣?似乎沒有工作夥伴我寫錯了嗎? – Webby 2010-06-09 21:49:41

+0

你說得對,我忘了一個'+'。我在http://regexpal.com/上測試了更新的版本,它工作正常。你可以省略'\ /?',它仍然可以工作。 – zildjohn01 2010-06-09 22:34:16

+0

真棒好友謝謝你! +1 – Webby 2010-06-09 23:13:13