MrAndre
MrAndre

Reputation: 1017

htaccess clean url for the profile page

When I try to do this in htaccess:

RewriteEngine on
RewriteRule ^([^\.]+)$ $1.php [NC,L]
ErrorDocument 404 /includes/errors/404.php
ErrorDocument 403 /includes/errors/403.php
RewriteRule ^profile/([^/]+)$ /profile?user=$1

It works but the name I read is wrong. When I do for example http://localhost/profile/Andre I get Andre.php as user and not Andre. Does someone know how to fix this?

Upvotes: 1

Views: 54

Answers (1)

Salketer
Salketer

Reputation: 15711

This happens because you rewrite according to your first rule, and since it is set as last, that's all that will happen. Try moving your profile rule above:

RewriteEngine on
RewriteRule ^profile/([^/]+)$ /profile?user=$1 [NC,L]
RewriteRule ^([^\.]+)$ $1.php [NC,L]
ErrorDocument 404 /includes/errors/404.php
ErrorDocument 403 /includes/errors/403.php

I also added [NC,L] to mark the rule as NoCase, and Last

Upvotes: 2

Related Questions