I have different dynamic page URLS and parameters as below. PHP .htaccess page.
http://localhost/index.php?city=Delhi
http://localhost/index.php?city=Delhi&page=AboutUs
http://localhost/index.php?city=Delhi&page=Blog&Read=AnyBlog
http://localhost/index.php?city=Delhi&page=Treatment&type=AnyTreatment
I want my URLs to be written like below.
http://localhost/Delhi
http://localhost/Delhi/AboutUs
http://localhost/Delhi/Blog/AnyBlog
http://localhost/Delhi/Treatment/AnyTreatment
Can any one help in rewriting code?
Easiest is to implement 4 separate rewrite rules:
RewriteEngine on
RewriteRule ^/?([^/]+)/Treatment/([^/]+)/?$ /index.php?city=$1&page=Treatment&Read=$2 [L]
RewriteRule ^/?([^/]+)/Blog/([^/]+)/?$ /index.php?city=$1&page=Blog&Read=$2 [L]
RewriteRule ^/?([^/]+)/([^/]+)/?$ /index.php?city=$1&page=$2 [L]
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteRule ^/?([^/]+)/?$ /index.php?city=$1 [L]
Those rules will work likewise, implemented in the http server's central virtual host configuration files, or, if you do not have access to that (read: if you are using a cheap hosting provider without access to the configuration), in a distributed configuration file (typically called ".htaccess"), if the consideration of such files is enabled for the http server's virtual host and location . Both will work, the second option comes with a number of disadvantages, but might be the only option for anyone not operating the http server himself.
You can simply test yourself: htaccess tester by "made with love"
It might be that you want to add the "case insentive matching" flag to your first two rules to match the terms "Blog" and "Treatment" in a case insensitive way. Just add the flag to the existing L
flag: [NC,L]