RUSHABH SHAH
RUSHABH SHAH

Reputation: 135

convert multiple Query String to seo friendly url in php

I have url Like http://somesite.com/packagemenu.php?conname=domestic-tours-packages&consubname=kerala-tours-packages

Now, i want to make it seo friendly with php code or htaccess rewriterule

my output should be look like this

http://somesite.com/domestic-tours-packages/kerala-tours-packages

Upvotes: 3

Views: 1450

Answers (2)

Amit Verma
Amit Verma

Reputation: 41219

If you want to redirect from querystring to short url, Try the following

 RewriteEngine on

RewriteCond %{THE_REQUEST} /packagemenu.php\?conname=([^&]+)&consubname=([^\s]+) [NC]
RewriteRule ^ /%1/%2? [NC,L,R]

#skip the rule if the request is for dir
RewriteCond %{REQUEST_FILENAME} !-d

 #skip the rule if the request is for file
 RewriteCond %{REQUEST_FILENAME} !-f
 #rewrite any other request  to "/packagemenu.php?" 
 RewriteRule ^([^/]+)/([^/]+)/?$ /packagemenu.php?conname=$1&consubname=$2 [NC,L]

shortest way to do it is as above!

Upvotes: 1

Thamilhan
Thamilhan

Reputation: 13303

Simply apply the rewrite rule like this:

RewriteEngine On
RewriteRule    ^([^/\.]+)/([^/\.]+)$    packagemenu.php?conname=$1&consubname=$2    [NC,L]  

Upvotes: 2

Related Questions