William Gibson
William Gibson

Reputation: 17

htaccess file not rewriting properly

I've got a problem in my .htaccess using Rewrite Rule. Here's my .htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?u=$1
RewriteRule ^([a-zA-Z0-9_-]+)/user/$ user.php?u=$1

The error is in the bottom two lines, where anybody going to /user/foo would see the result of going to /user?u=foo.

Upvotes: 1

Views: 22

Answers (2)

hjpotter92
hjpotter92

Reputation: 80639

Try this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_FILENAME}.php [NC,L]
RewriteRule ^/?user/([\w-]+)/?$ user.php?u=$1 [L]

Upvotes: 1

Croises
Croises

Reputation: 18671

You can use:

RewriteEngine On

RewriteRule ^user/(.+)/?$ user.php?u=$1 [NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

Upvotes: 1

Related Questions