【发布时间】:2017-09-20 18:13:58
【问题描述】:
我是 mod rewrite 的新手,我在尝试为我们的私人论坛用户实现以下目标时遇到了问题。私人论坛位于站点的子目录中,名为community
用户点击电子邮件链接:
https://www.example.com/community/index.php?/topic/this-is-the-topic
当浏览器进入论坛并且用户未登录时。论坛将/login/注入{QUERY_STRING},尽管它没有显示在URL中并且它们被定向到网站登录页面,这是唯一的方法根据所需的 RewriteRule 判断用户是否已登录。
到达登录页面时,URL 需要如下所示:
https://www.example.com/login.php?redirect_to=https://www.example.com/community/index.php?/topic/this-is-the-topic
我尝试过的是:
RewriteCond %{QUERY_STRING} /login/(.*)$ [NC]
RewriteRule ^(.*)$ https://www.example.com/login.php?redirect_to=%{REQUEST_URI} [L,R=301]
这让我明白了:
https://www.example.com/login.php?redirect_to=/community/index.php
问号后面的所有东西都不见了……
如果我在 RewriteRule 中的 {REQUEST_URI} 之后添加 %{QUERY_STRING},您可以看到 login 已在 {QUERY_STRING} 中的 /community 之后注入,然后是包含 Base64 编码版本的 &ref=电子邮件中的原始引用 URL。
更新:
社区是社区子目录中的私人论坛 并且有 2 个 .htaccess 文件,一个在根目录中,另一个在社区目录中。
我继承了这个,对我来说 htaccess 文件看起来有点乱 我们需要确保所有 http 流量都被强制到 https
根 .htaccess 文件
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTPS_HOST} !^tribe.mytechnologybusiness.com$ [NC]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule (.*) https://tribe.mytechnologybusiness.com/$1 [L,R=301]
# End Replacement
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# BEGIN MainWP
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^wp-content/plugins/mainwp-child/(.*)$ /wp-content/plugins/THIS_PLUGIN_DOES_NOT_EXIST [QSA,L]
</IfModule>
# END MainWP
社区 .htaccess 文件
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
############################################
# WordPress to IPBoard Integration
# Start Board to Wordpress Redirect Area
############################################
RewriteEngine on
# Registration
RewriteCond %{QUERY_STRING} /register/(.*)$ [NC]
RewriteRule (.*) https://tribe.mytechnologybusiness.com/wp-login.php?action=register [L,R=301]
# Logout
RewriteCond %{QUERY_STRING} /logout/(.*)$ [NC]
RewriteRule (.*) https://tribe.mytechnologybusiness.com/wp-login.php?action=logout [L,NE,R=301]
# Login
RewriteCond %{QUERY_STRING} /login/(.*)$ [NC]
RewriteRule ^(.*)$ https://tribe.mytechnologybusiness.com/wp-login.php?redirect_to=%{REQUEST_URI} [L,R=301]
############################################
# End Board to Wordpress Redirect Area
############################################
我试图用来测试的网址是
https://tribe.mytechnologybusiness.com/community/index.php?/topic/162-sydney-tribal-meetup-thursday-14th-september-2017/
谁能帮我解决这个问题?
干杯,
【问题讨论】:
标签: .htaccess mod-rewrite