0

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

2
  • "not working" is insufficient. Explain what is happening and what you have done to debug. Commented Jan 5, 2016 at 8:08
  • when i add this code its show url not found Commented Jan 5, 2016 at 8:48

1 Answer 1

1

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]
Sign up to request clarification or add additional context in comments.

4 Comments

i have add the code but now css and js not loading when i use this code
my css files are example.com/directory1/directory2/style.css now what should i do
You can add this just below <head> section of your page's HTML: <base href="/directory1/directory2/" />
yes its working fine can you please tell me if i want to remove the directroy from url means example.com/directory1/directory2/test.php?id=8 to example.com//test/8 is it possible

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.