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

时间:2015-12-16 07:36:28

标签: php .htaccess mod-rewrite

我有网址赞http://somesite.com/packagemenu.php?conname=domestic-tours-packages&consubname=kerala-tours-packages

现在,我想用php代码或htaccess rewriterule

使它变得友好

我的输出应该是这样的

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

2 个答案:

答案 0 :(得分:2)

只需应用这样的重写规则:

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

答案 1 :(得分:1)

如果要从查询字符串重定向到短网址,请尝试以下

 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]
最简单的方法就是如上所述!