如何使用 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=&database= [L,QSA,NC]
我的网站有动态页面,例如
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=&database= [L,QSA,NC]