I have some question to ask about rewrite url in php.
1- http://www.test.com/index.php?name=123 to http://www.test.com/123
2- http://www.test.com/folder1/index.php?name=123 to http://www.test.com/folder1/123/index.php
Hereabout my coding on number 1 but i don’t know how to rewrite number 2 combination with number 1:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?usname=$1 [QSA,L]
When you say “rewrite url in php”, I assume that “in php” refers to the language of the application, not the rewrite/redirect method — because your example code consists of Apache directives.
The rules below will change URLs in the form test.com/folder1/index.php?name=123 into a “pretty” URL of the form test.com/folder1/123 (I removed the ‘index.php’ to be even more user-friendly).
Redirect the ugly query URL so users always see the “pretty” URL
Tell the server how to interpret the pretty URL
NOTE:
The first rule above uses a 302 (temporary) redirect, so your browser doesn’t “memorize” the redirect rule while you’re testing and tweaking them. If you care about SEO, change the
[R=302]to[R=301], which is a permanent redirect.