2011-03-22 528 views
0

我已經成功地建立了一個重定向像這樣快捷方式的URL系統:的.htaccess重寫規則幫助

# http://www.site.com/102/ -> http://www.site.com/102-some-keywords.html 
RewriteRule ^([0-9]{3})/?$ includes/redirect.php?ref=$1 [L] 
# http://www.site.com/102-some-keywords.html -> http://www.site.com/templates/default/index.php?ref=102 
RewriteRule ^([0-9]{3})-.*?\.html$ templates/default/index.php?ref=$1 [L] 

現在我升級到一個多語言系統,並希望域之後獲得語言代碼:

# http://www.site.com/fr/102/ -> http://www.site.com/fr/102-some-keywords.html 
# http://www.site.com/fr/102-some-keywords.html -> http://www.site.com/templates/default/index.php?loc=fr&ref=102 

一些語言是法國,意大利,ES,RU,... 我想我需要多個變量$ 1,$ 2,但我堅持這部分內容。

這是一個嘗試(工作不正常)

RewriteRule ^(.+)/(^[0-9]{3})/?$ includes/redirect.php?loc=$1&ref=$2 [L] 
RewriteRule ^(.+)/(^[0-9]{3})-.*?\.html$ templates/default/index.php?loc=$1&ref=$2 [L] 

回答

0

你的新代碼基本上是正確的,但您[0-9]之前忘了^(表達的比賽開始)。僅僅取消這些應使代碼的工作,但我個人更嚴格的添加匹配的國家代碼:[a-z]{2}

RewriteRule ^([a-z]{2})/([0-9]{3})/?$ includes/redirect.php?loc=$1&ref=$2 [L] 
RewriteRule ^([a-z]{2})/([0-9]{3})-.*?\.html$ templates/default/index.php?loc=$1&ref=$2 [L]