301仅在URI不包含特定字符串的情况下重定向 [英] 301 redirect only if URI doesn't contain specific string
问题描述
我有一个drupal网站,该网站已分为两个单独的网站,现在我需要设置一些重写规则,以将流量吸引到新网站。
I have a drupal website which has been split up to two separate websites, and now I need to setup some rewrite rules in order to drive traffic to the new site.
原始网站如下:
http://www.website.com (frontpage)
http://www.website.com/web1/subpage1 (subpage)
http://www.website.com/web1/subpage2 (subpage)
http://www.website.com/subpage3 (subpage)
http://www.website.com/subpage4 (subpage)
全部对不在web1类别中的子页面的引用已从网站中删除,但这些页面仍已发布,并且仍显示在Google中。
All references to subpages that are not in the web1-category have been removed from the website, but the pages are still published and they still show up in Google.
我需要什么是一种重写规则,如果用户尝试访问不是首页也不在web1类别中的页面,则该规则将从 website.com重定向到 new-website.com的首页。
What I need is a rewrite rule that redirects from "website.com" to the frontpage of "new-website.com" if the user tries to access a page that is not the frontpage and not in the web1-category.
我想以重写规则检查URI中的字符串 web1将解决我的问题,但不幸的是,我不知道如何编写语法。
I suppose a rewrite-rule checking for the string "web1" in the URI would be the answer to my problem, but unfortunately I have no idea how to write the syntax.
任何帮助将不胜感激。
预先感谢。
编辑:
我的带有@zessx的htaccess文件建议的解决方案:
My htaccess file with @zessx proposed solution:
Options -Indexes
Options +FollowSymLinks
DirectoryIndex index.php
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^my-website\.com$ [NC]
RewriteRule ^(.*)$ http://www.my-website.com/$1 [L,R=301]
RewriteCond %{REQUEST_URI} !web1
RewriteRule ^(.+)$ http://www.my-new-website.com [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
推荐答案
这就是您需要的:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !web1
RewriteRule ^(.+)$ http://new-website.com [L,R=301]
这篇关于301仅在URI不包含特定字符串的情况下重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!