0

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)

2
  • It would be good to know what doesn't work. Do you get an error from the server? Commented Jul 3, 2011 at 18:12
  • @Enyo When I'm having those settings it just says: Not Found The requested URL /profil/(username) was not found on this server. Commented Jul 3, 2011 at 18:13

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your help, and thanks for the link :o) I'll mark you as the correct answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.