rockhopper
rockhopper

Reputation: 85

.htaccess Multiple rewrites?

I want to rewrite to multiple pages.

I want an request to mysite.com/home to be rewritten to mysite.com/home.php and a request to mysite.com/u/erty5000 to be rewritten to mysite.com/profile.php?u=erty5000 using a .htaccess file.

Is this possible? And if it is, how?

So far this is how I rewrite request from mysite.com/home to mysite.com/home.php

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ /$1.php [L,QSA]

Thanks in advance! :D

Upvotes: 1

Views: 77

Answers (1)

Olaf Dietsche
Olaf Dietsche

Reputation: 74018

You already have the first rule. You must exclude the u/... request however. Add a RewriteCond, which does this

RewriteCond %{REQUEST_URI} !^/u/

The second rewrite works similar. Extract the needed part from the request and use it in the substitution

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

Upvotes: 1

Related Questions