2013-04-27 68 views
1

我剛剛得到的重寫引擎加載和活躍,但無法弄清楚 如何設計一個良好的.htaccess文件。 我想要變換這樣的鏈接:url-rewrite&如何設置它與htaccess

http://localhost/index.php?u=username --> http://localhost/username/ 
http://localhost/index.php?id=1&v=2 --> http://locahost/1x2 

感謝您的幫助!

+0

你的意思是將用戶輸入(左)是那些獲得縮短(如右圖所示)長的網址? – 2013-04-27 16:29:12

+0

我的意思是用戶在右側輸入較短的url地址 – dash 2013-04-27 16:34:43

+0

並且地址欄中的URL應該保留「localhost/username」還是改爲「index.php?u = username」? – 2013-04-27 16:38:22

回答

1

URL重寫改變:

HT * P://本地主機/用戶名/ - 與/結束可選
到> HT * P://localhost/index.php U =?用戶名

HT * p://本地主機/ 1x2的 - 不區分大小寫(匹配4X4)
至> HT * p://localhost/index.php ID = 1 & v = 2

的.htaccess內容:

RewriteEngine On 

RewriteBase/

RewriteCond %{HTTP_HOST} ^localhost$ [NC] 
RewriteCond %{REQUEST_URI} !^/index.php [NC] 
RewriteCond %{REQUEST_URI} ^/([^/\d]+)/?$ [NC] 
RewriteRule (.*) index.php?u=%1 [L] 

RewriteCond %{HTTP_HOST} ^localhost$ [NC] 
RewriteCond %{REQUEST_URI} ^/(\d+)x(\d+)/?$ [NC] 
RewriteRule (.*) index.php?id=%1&v=%2 [L] 
+0

對不起我的模糊問題,我與正則表達式不好。 謝謝你,Ravi爲了這個輝煌的工作 - 那就是把戲:) – dash 2013-04-27 17:36:09

+0

iam很開心吧! – dash 2013-04-27 17:41:18

+0

@dash很高興幫助。投票也可以嗎? :) – 2013-04-27 17:47:10