简体   繁体   English

仅当不存在URL查询字符串时,才在子域上重定向页面

[英]Redirect page on subdomain only when no URL query string is present

Pretty specific htaccess question: I have a page at http://subdomain.example.com/page/ that contains a form. 非常具体的htaccess问题:我在http://subdomain.example.com/page/上有一个包含表单的页面。 The page should only be accessed with auto-created links that contain query strings that feed information through the form. 仅应使用包含查询字符串的自动创建链接访问该页面,查询字符串通过表单提供信息。 What I need is an htaccess rule that will redirect traffic coming to this page to my homepage at http://example.com/ whenever it is reached without a query string in the URL. 我需要的是htaccess规则,该规则可将到达此页面的访问量重定向到http://example.com/上的我的主页,只要访问量在URL中没有查询字符串即可。

Put another way: if someone reaches http://subdomain.example.com/page/ they need to redirect to http://example.com . 换句话说,如果有人到达http://subdomain.example.com/page/,他们需要重定向到http://example.com But if someone reaches http://subdomain.example.com/page/?querystring they need to stay on the page. 但是,如果有人到达http://subdomain.example.com/page/?querystring,他们需要停留在页面上。

How do i solve this with htaccess? 如何使用htaccess解决此问题?

try: 尝试:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com$ [NC]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^page/ http://example.com/ [L,R]

or 要么

RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com$ [NC]
RewriteCond %{THE_REQUEST} !\?
RewriteRule ^page/ http://example.com/ [L,R]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM