仅当 URI 不包含特定字符串时才进行 301 重定向 [英] 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.
任何帮助将不胜感激.
提前致谢.
我的 htaccess 文件与@zessx 提出的解决方案:
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]
这篇关于仅当 URI 不包含特定字符串时才进行 301 重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!