Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 重写包含。。。在htaccess中_Php_Regex_.htaccess_Mod Rewrite - Fatal编程技术网

Php 重写包含。。。在htaccess中

Php 重写包含。。。在htaccess中,php,regex,.htaccess,mod-rewrite,Php,Regex,.htaccess,Mod Rewrite,有时我发现我网站上的URL显示为mywebsite\u smf\u smf1\u 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​u5fnl1qmj7te

有时我发现我网站上的URL显示为
mywebsite\u smf\u smf1\u 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\u smf\u smf1\u session=####
的部分不应在URL中,但链接仍会重定向到正确的页面

我想知道如何在.htaccess中使用mod#u rewrite,以便当有人单击包含
mywebsite_smf#u smf1_session=###和
的URL时,它会自动恢复到不包含它的版本:

点击:

http:// mywebsite.com/index.php​?我的网站\u smf\u smf1\u会话=6gqvo88l​u5fnl1qmj7temt0113&主题=316196​.msg931242

变成:

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


您可以在
文档\u ROOT/.htaccess
文件中使用此规则:

RewriteEngine On

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

听起来你有更大的问题。我想你使用的是论坛软件包,你的数据库用户名是mywebsite\u smf。没有真正的理由认为论坛包应该制作这些类型的链接——会话令牌最好在cookie中完成。请查看配置文件,如果可能,请升级系统!看起来很容易受到各种攻击,我同意。我知道问题出在哪里,但我需要一个快速修复来止血。谢谢@anubhava,但我得到了一个404错误。​?**我的网站\u smf\u smf1\u会话=5lj4j3fi​5g2mc2sa5r9jtb5645&**动作=加勒​这不是一个好主意​?动作=加勒​瑞耶,不幸的是,它不起作用了。我像你说的那样将它添加到了.htaccess,当我访问包含smf1_会话的网站时,它会重定向到404错误,页面未找到。(点)com部分呢?检查您的URL,因为它可能有一些不可打印的字符。这个规则在我的Apache上运行良好,使用
/index.php?mywebsite\u smf\u smf1\u session=5lj4j3fi%E2%80%8B5g2m‌​c2sa5r9%E2%80%8C%E2%80%8Bjtb5645&action=gallery
并删除第一个查询参数。