Reputation: 1754
I have a problem rewritting /authentication/view_profile?user=(username) to myurl.com/profil/(username)
Right now my .htaccess file is:
RewriteEngine On
#Rewrite /view.php?vis=id to /opslag/vis/id
#RewriteRule ^opslag/vis/(\d+)$ /opslag/view.php?vis=$1 [NC,QSA,L]
#Rewrite authentication/view_profile.php?user=* to profil/*
RewriteRule ^profil/(\d+)$ /authentication/view_profile.php?user=$1 [NC,QSA,L]
#Remove index.php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]
#Remove /page/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
I'm already using a rule to rewrite another one, which is the "#Rewrite view.php?vis=id to /opslag/vis/id
Right now my URL's look like this:
<a href='/profil/$_SESSION[username]'>Vis profil</a>
I hope you wanna help me.
If you need some details please just tell me.. :o)
Upvotes: 0
Views: 540
Reputation: 165511
Use this one instead:
RewriteRule ^profil/([^/]+)$ /authentication/view_profile.php?user=$1 [NC,QSA,L]
Your rule can only accept usernames if they consist of digits only (\d+)
. This one ([^/]+)
will accept any characters (except /
, which is a folder delimiter).
P.S. Consider reading this Introduction to regular expressions and mod_rewrite if you plan to use .htaccess and URL rewrite rules on regular basis.
Upvotes: 4