允许htaccess上的查询字符串直接传递

时间:2018-11-08 19:20:53

标签: wordpress .htaccess

我已经在.htaccess上实现了以下设置。

https://example.com/-WordPress主要网站
https://example.com/forum-SMF论坛网站

论坛网站以前曾经在https://example.com上,而我最近已将其移至/forum。为了使诸如https://example.com/index.php?topic=29414.new;topicseen#new之类的旧链接有效,我在.htaccess中添加了特定规则。所有这一切都很好。

我的问题是,在我的WordPress网站上,我具有某些使用查询字符串的链接,例如:https://example.com/?et_fb=1https://example.com/?preview=true,但是这些链接都被忽略了,或者现在就转到主页。这些查询字符串链接通常是诸如在Wordpress网站上预览帖子,页面构建器链接等之类的东西。感谢所有帮助以解决此问题。

RewriteEngine on
RewriteRule ^index.php/(.*)$ /forum/index.php/$1 [L,R]
# if query string is present
RewriteCond %{QUERY_STRING} .+
# redirect "/index.php" to "/forum/index.php
RewriteRule ^index.php$ /forum/index.php [L,R]

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} "fbclid=" [NC]
RewriteRule (.*) /$1? [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

1 个答案:

答案 0 :(得分:0)

问题是任何带有查询字符串的URL都将发送到您的/forum。为了解决冲突,您需要更加具体。

因此,您要么需要选择性,要么仅将具有特定查询字符串的URL发送到/forum,例如以topic=开头的URL。或者,创建例外,然后 not 将包含与WordPress_相关的某些查询字符串的URL发送到您的/forum。较小者为准。

例如,仅将包含topic=的URL发送到您的/forum

RewriteCond %{QUERY_STRING} ^topic=
RewriteRule ^index\.php$ /forum/index.php [L,R]

或者,防止将包含et_fb=preview=的URL发送到您的论坛(所有其他内容都发送到您的论坛):

RewriteCond %{QUERY_STRING} !^(et_fb|preview)=
RewriteRule ^index\.php$ /forum/index.php [L,R]