user3058067
user3058067

Reputation: 327

how to use mod_rewrite .htaccess

Hello i want to rewrite the following link:

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

to http://websoftit.ro/social/Ancuta Mirela. Can someone tell me how to do that with mod_rewrite also maybe give me a link to a good documentation to learn myself how to do that? Thnx in advance.

Upvotes: 1

Views: 112

Answers (3)

anubhava
anubhava

Reputation: 785058

You can use this code in your DOCUMENT_ROOT/.htaccess file:

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]

I would suggest http://askapache.com as a good reference for learning mod_rewrite.

Upvotes: 3

user2706194
user2706194

Reputation: 199

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

Upvotes: 0

AO_
AO_

Reputation: 2874

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

Upvotes: 0

Related Questions