Ryan Smith
Ryan Smith

Reputation: 81

URL Rewrite Module messing with $_GET variables

I've established a semi-working .htaccess file which alters this link:

localhost/profile.php?id=6

to this:

localhost/profile/6

However, this is adding .php to the end of my $_GET variables. I'm not very familiar with rewrite modules, .htaccess etc but this is very annoying. Couldn't find anything on the internet about it, if there is a different way to do it or fix it I would greatly appreciate any input.

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

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^profile/(.*) profile.php?id=$1
</IfModule>

Upvotes: 1

Views: 49

Answers (1)

nicael
nicael

Reputation: 18995

Try restricting to only numbers:

RewriteRule ^profile/(\d*) profile.php?id=$1

Or exclude ., if the ID is not certainly numeric:

RewriteRule ^profile/([^.]*) profile.php?id=$1

Upvotes: 1

Related Questions