簡體   English   中英

301僅在URI不包含特定字符串時才重定向

[英]301 redirect only if URI doesn't contain specific string

我有一個drupal網站,它被分成兩個獨立的網站,現在我需要設置一些重寫規則,以便為新網站帶來流量。

原始網站看起來像這樣:

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中。

我需要的是一個重寫規則,如果用戶試圖訪問不是首頁而不是web1類別的頁面,則從“website.com”重定向到“new-website.com”的首頁。

我想在URI中檢查字符串“web1”的重寫規則將是我的問題的答案,但不幸的是我不知道如何編寫語法。

任何幫助,將不勝感激。

提前致謝。


編輯:

我的htaccess文件與@zessx提出了解決方案:

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]

我的一位同事找到了解決方案:

RewriteCond %{REQUEST_URI} !^/web1(/|$)
RewriteCond %{REQUEST_URI} !^/admin(/|$)
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^([\w/]*)$ http://www.new-website.com [L]`

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM