Kline Moralee
Kline Moralee

Reputation: 1

.htaccess mod_rewrite and Query Strings

In my .htaccess file I've got a rule that strips the .php:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

So, /mydomain.com/page.php becomes /mydomain.com/page/ - Which works fine.

Now I'm trying to achieve something similar with query strings, where:

/mydomain.com/page.php?variable=value becomes /mydomain/page/value/

I've tried numerous methods and the best I can get is /mydomain/page/?variable=value

Upvotes: 0

Views: 162

Answers (1)

joshuahealy
joshuahealy

Reputation: 3569

Your second rule is

RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php

You can change this to rewrite to a query param like this:

RewriteRule ^([^/]+)/([^/]+)/$ /$1.php?variable=$2

Upvotes: 1

Related Questions