如何使用mod_rewrite .htaccess

时间:2014-02-28 11:13:45

标签: .htaccess mod-rewrite

您好我想重写以下链接:

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

http://websoftit.ro/social/Ancuta Mirela。 有人可以告诉我如何使用mod_rewrite也可以给我一个良好的文档链接,以了解自己如何做到这一点? Thnx提前。

3 个答案:

答案 0 :(得分: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的好参考。

答案 1 :(得分:0)

RewriteEngine On
RewriteRule ^social/([^/]+)$ social/profil.php?user=$1

答案 2 :(得分:0)

RewriteCond %{QUERY_STRING} (?:^|&)user=([^&]+) [NC]
RewriteRule ^ http://websoftit.ro/social/%1 [NE,R=301,L]
相关问题