2014-02-28 43 views
1

你好,我想下面的鏈接改寫:如何使用mod_rewrite的.htaccess

http://websoftit.ro/social/profil.php?user=Ancuta Mirela 

http://websoftit.ro/social/Ancuta Mirela。 有人可以告訴我如何做到這一點,也可以給我一個鏈接到一個很好的文檔來學習自己如何做到這一點mod_rewrite? Thnx提前。

回答

3

您可以在DOCUMENT_ROOT/.htaccess文件中使用此代碼:

RewriteEngine On 

RewriteCond %{THE_REQUEST} \s/+social/profil\.php\?user=([^\s&]+) [NC] 
RewriteRule^/social/%1? [R=302,L] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^social/([^/]+)/?$ /social/profil.php?user=$1 [L,QSA] 

我建議http://askapache.com作爲學習mod_rewrite一個很好的參考。

+0

hehe thnx很多,它真的與你的方法一起工作,我真的不知道你從哪裏得到這些[^/+或者它們是什麼意思,但它的工作,我希望我想從該鏈接學習寫我自己的規則:D – user3058067

+0

但仍然,如果我想添加一個像ID一樣的參數來獲得它與$ _GET它是posible?如果我重寫url – user3058067

+0

是的使用相同的模式,你可以使用任何參數。如果您遇到任何問題,請告知我,我會協助您。 – anubhava

0
RewriteEngine On 
RewriteRule ^social/([^/]+)$ social/profil.php?user=$1 
0
RewriteCond %{QUERY_STRING} (?:^|&)user=([^&]+) [NC] 
RewriteRule^http://websoftit.ro/social/%1 [NE,R=301,L]