在php中将多个查询字符串转换为seo友好的url



我有类似http://somesite.com/packagemenu.php?conname=domestic-tours-packages&consubname=kerala-tours-packages 的url

现在,我想用php代码或htaccess重写器使其对seo友好

我的输出应该像这个

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

只需应用如下重写规则:

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

如果您想从querystring重定向到短url,请尝试以下

 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]

最短的方法是如上所述!

最新更新