.htaccess将特定域重定向到特定页面 [英] .htaccess redirect specific domain to specific page

查看:88
本文介绍了.htaccess将特定域重定向到特定页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望来自urlnumberone.com和urlnumbertwo.com的任何流量都重定向到我网站上的几个特定页面。

I want any traffic coming from urlnumberone.com and urlnumbertwo.com to redirect to a couple of specific pages on my site.

RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://(www.\.)?urlnumberone\.com
RewriteRule ^$ /thepath/tomypage/goeshere/ [L]

RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://(www.\.)?urlnumbertwo\.com
RewriteRule ^$ /thesecond/pathgoeshere/ [L]

现在,两个URL都只是将用户带到我网站的主页上,而不是转到我打算的页面。我究竟做错了什么?如果需要的话,该站点是WordPress站点,并且WordPress规则位于这些重定向之下,而不是位于代码上方。

Right now, both URLs are simply taking the user to the homepage on my site, rather than going to the pages I've intended. What am I doing wrong? In case it matters, the site is a WordPress site and the WordPress rules are UNDER these redirects, not above them in the code.

推荐答案

<我认为有两个问题。 RewriteCond 行中有一个额外的点,因此括号中的部分当前表示 www(any-character)(literal-dot),这将阻止与www匹配您需要匹配的域的版本-除非您尝试匹配 www6.urlnumberone.com www3.urlnumberone.com之类的域

I think there are two issues. There is an extra dot in the RewriteCond lines, so the portion in parentheses currently means "www(any-character)(literal-dot)", which would prevent matching the www version of the domain that you need to match -- unless you're trying to match domains like www6.urlnumberone.com and www3.urlnumberone.com.

因此,我将替换为:

RewriteCond%{HTTP_REFERER} ^ http://(www.\。)?urlnumberone\.com

With:

RewriteCond%{HTTP_REFERER} ^ http://(www\。)?urlnumberone\.com

接下来,对于 RewriteRule 行,我将更改 ^ $ (替换为空字符串)。* (替换整个路径),并使用302或301重定向。由于WordPress会重写每个不存在的文件或目录的URL,因此很容易错误地导致重定向循环,因此使用301或302应该可以避免这种情况。所以我会用:

Next, for the RewriteRule line, I would change the ^$ (replacing an empty string) with .* (replacing the whole path), and use a 302 or 301 redirect. Since WordPress rewrites every URL that isn't an existing file or directory, it's easy to make redirect loops by mistake, so using a 301 or 302 should help prevent that. So I would use:

RewriteRule。* / thepath / tomypage / goeshere / [R = 302,L]

可能有mod_rewrite向导有更好的答案,但是根据我的经验,这种方法效果很好。

There may be mod_rewrite wizards out there that have a better answer, but this method works well in my experience.

这篇关于.htaccess将特定域重定向到特定页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆