Deepak Goyal
Deepak Goyal

Reputation: 1216

.htaccess rewrite query string as path with multiple directory

I m trying to do a very simple rewrite of a query string

http://www.example.com/directory1/directory2/test.php?id=8

to

http://www.example.com/directory1/directory2/test/8

and my code is

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?test/(.*?)/?$ /test.php?id=$1 [L]

nut its not working i also try many solution provided on stackoverflow but nothing work please help me

Upvotes: 0

Views: 217

Answers (1)

anubhava
anubhava

Reputation: 785108

Place this rule in /directory1/directory2/

Options -MultiViews
RewriteEngine On
RewriteBase /directory1/directory2/

RewriteCond %{THE_REQUEST} /test\.php\?id=([^\s&]+) [NC]
RewriteRule ^ test/%1? [R=302,L,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^test/(\w+)/?$ test.php?id=$1 [L,QSA,NC]

Upvotes: 1

Related Questions