【问题标题】:301 Redirects (htaccess) with exclude conditions具有排除条件的 301 重定向 (htaccess)
【发布时间】:2012-01-23 14:11:09
【问题描述】:

我目前正在将网站(商店)移动到新域,并在其位置放置该网站的非商店版本(用 wordpress 制作)。目的是让大多数 url 重定向到新域,除了新站点的少数页面。我在 stackoverflow 上找到了其他帖子,但不幸的是我似乎无法让它工作。任何帮助将不胜感激,谢谢 Jason。

我需要排除的网址是: / (主页) /news 及其帖子 /news/post-name /products 及其帖子 /products/post-name /offers 及其帖子 /offers/post-name /我们的理念 /我们的队伍 /我们的梦想

这是我尝试过的:

<IfModule mod_rewrite.c>

RewriteEngine on

#Home
RewriteCond %{REQUEST_URI} !^/

#News
RewriteCond %{REQUEST_URI} !^/news(.*)

#Products
RewriteCond %{REQUEST_URI} !^/products(.*)

#Offers
RewriteCond %{REQUEST_URI} !^/offers(.*)

#Philosophy
RewriteCond %{REQUEST_URI} !^/our-philosophy(.*)

#Team
RewriteCond %{REQUEST_URI} !^/our-team(.*)

#Dream
RewriteCond %{REQUEST_URI} !^/our-dream(.*)

RewriteRule (.*) http://www.cotswold-fayre.co.uk/$1 [R=301,L]

</IfModule>



# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

【问题讨论】:

  • 这应该是服务器故障,与编程无关..

标签: .htaccess mod-rewrite redirect url-rewriting http-status-code-301


【解决方案1】:

尝试将以下内容添加到您的 .htaccess 文件中

RewriteEngine on

#Home: Exclude the home Page
RewriteCond %{REQUEST_URI} !^/$ [OR]

#News: exclude anything that starts with /news, /products etc
RewriteCond %{REQUEST_URI} !^/(news|products|offers|our-philosophy|our-team|our-dream) [NC]

RewriteRule (.*) http://www.cotswold-fayre.co.uk/$1 [R=301,L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-23
    • 2018-01-22
    • 1970-01-01
    • 2018-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多