mod_rewrite 除两个 URL 之外的所有内容
我正在尝试重写除以下两个网址之外的所有内容 google.com(可以是任何外部网址,但 google 用于测试)。
w3ink.com/wp/folder/wp-admin
w3ink.com/wp/folder/schedule-the-truck
转到网站上的页面。
其他所有内容都转到 google.com
这是到目前为止我在 documentRoot 中的 .htaccess 文件中所拥有的内容:
RewriteCond %{REQUEST_URI} !^/wp/folder/schedule-the-truck$
RewriteCond %{REQUEST_URI} !^/wp/folder/wp-admin$
RewriteRule .* "http://google.com" [R=301,L]
它不起作用。所有内容都会转发到 google.com,甚至是我的否定条件语句中的两页。
I am trying to rewrite everything EXCEPT the below two urls to
google.com (could be any external url, but google for testing).
w3ink.com/wp/folder/wp-admin
w3ink.com/wp/folder/schedule-the-truck
goes to pages on site.
everything else goes to google.com
Here's what I have so far in my .htaccess file in documentRoot:
RewriteCond %{REQUEST_URI} !^/wp/folder/schedule-the-truck$
RewriteCond %{REQUEST_URI} !^/wp/folder/wp-admin$
RewriteRule .* "http://google.com" [R=301,L]
It just doesn't work. Everything gets forwarded to google.com, even the two pages in my negative condition statements.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该启用
mod_rewrite
调试日志记录。这可能会告诉您,对于.htaccess
文件,REQUEST_URI
不以斜杠开头。 (即使我的假设是错误的,它也会向您显示发生的所有步骤,这应该给您一个提示为什么它们会发生。You should enable the
mod_rewrite
debug logging. This might probably show you that for.htaccess
files, theREQUEST_URI
does not start with a slash. (And even if my assumption is wrong, it will show you all steps that happen, which should give you a hint to why they happen.尝试删除重写条件末尾的
$
。由于
wp-admin
是一个目录,因此服务器重定向到wp-admin/
。然后您的重写规则将其重定向到http://www.google.com/
。Try removing the
$
at the end of the rewrite conditions.Because
wp-admin
is a directory, the server redirected towp-admin/
. Then your rewrite rule redirected that tohttp://www.google.com/
.