如何使用htaccess或其他技术从url中删除多个查询字符串变量


how to remove multiple query string variable from url using htaccess or other technique

我的网站有动态页面,如

http://www.example.com/detailpage.php?sn=1%20&&%20database=news
http://www.example.com/detailpage.php?sn=1%20&&%20database=article
http://www.example.com/detailpage.php?sn=1%20&&%20database=interview

以及许多其他

我想从url中删除或隐藏查询字符串变量并显示为

http://www.krishisansar.com/detailpage/news/1
http://www.krishisansar.com/detailpage/article/1

是否可以将查询字符串更改为斜杠?如果没有,如何删除&并制作为

/news=1 or /news=2, 
/article=1 or /article=2 .

通过此操作,我可以从w3c进行验证。

您可以在DOCUMENT_ROOT/.htaccess文件中使用以下代码:

Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /detailpage'.php'?sn=([^'s&]+)&database=([^'s&]+) [NC]
RewriteRule ^ detailpage/%2/%1? [R=302,L,NE]
RewriteRule ^detailpage/('w+)/('d+)/?$ detailpage.php?sn=$2&database=$1 [L,QSA,NC]