重写包含..的URL..在htaccess中


Rewrite URL containing ... in htaccess

有时我发现我网站上的URL显示为mywebsite_smf_smf1_session=

例如:

http://mywebsite.com/index.php​?mywebsite_smf_smf1_session=6goevo28​vf18ubqgb5uh6r08b2&topic=332242​.msg916981
http://mywebsite.com/index.php​?mywebsite_smf_smf1_session=6gqvo88l​u5fnl1qmj7temt0113&topic=316196​.msg931242

包含mywebsite_smf_smf1_session=###的部分不应该在URL中,但链接仍然重定向到正确的页面。

我想知道如何在.htaccess中使用mod_rewrite,这样当有人单击包含mywebsite_smf_smf1_session=###&的URL时,它会自动恢复到不包含它的版本:

点击:

http://mywebsite.com/index.php​?mywebsite_smf_smf1_session=6gqvo88l​u5fnl1qmj7temt0113&主题=316196​.msg931242

成为:

http://mywebsite.com/index.php​?主题=316196​.msg931242

您可以在DOCUMENT_ROOT/.htaccess文件中使用此规则:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^mywebsite_smf_smf1_session=[^&]*(?:&(.*))?$ [NC]
RewriteRule ^index'.php$ %{REQUEST_URI}?%1 [NE,L,NC,R=302]