jardane
jardane

Reputation: 471

Simple .htaccess rewrite for _get variable

I am working on a site that uses pages with _get variables for example you can get to www.thewebsite.com/users.php?uservar=username by just using www.thewebsite.com/users/username.

The issue I run into is when I also try to add in url rewrites that also cut off file extenuation so aboutus.php becomes about us.

Can I have these two functions in one .htaccess file?

I tried this but it did not seem to work well

RewriteEngine on
RewriteRule ^([^/\.]+)/?$ /user.php?page=$1 [L]

Upvotes: 0

Views: 54

Answers (1)

Jon Lin
Jon Lin

Reputation: 143966

You can have both at the same time, but you need the routing rule (the one that targets user.php) to be below the rule that tries to re-attach the extension. So something like this:

# whatever rule you have to re-attach the extension:
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ /$1.php [L]

# now your user routing rule, make sure you add the condition:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ /user.php?page=$1 [L]

Upvotes: 1

Related Questions