htaccess 301重定向整个站点,但有例外 [英] htaccess 301 redirect entire site but with exceptions

查看:48
本文介绍了htaccess 301重定向整个站点,但有例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除某些例外,我正在尝试创建htaccess文件来重定向我的整个网站,但是我无法使其正常运行.我需要重定向整个内容,提供特定的重定向,并排除两个页面.以下是我无法正常工作的示例.谢谢!

I am trying to create an htaccess file to redirect my entire site except with some exceptions, but I can't get it working. I need to redirect the entire thing, provide a specific redirect, and exclude two pages. Below is my non-working sample. Thanks!

RewriteCond %{REQUEST_URI} !^/events/index.html
RewriteCond %{REQUEST_URI} !^/calendar/index.html
Redirect 301 /info/faq.html http://mynewsite.com/my-page
Redirect 301 / http://mynewsite.com

推荐答案

您正在尝试将mod_rewritemod_alias混合使用,但是RewriteCond语句不能对Redirect语句进行条件设置,因为它们不会来自同一模块.

You're attempting to mix mod_rewrite with mod_alias, but the RewriteCond statements cannot condition the Redirect statements, as they don't come from the same module.

如果我正确理解了您要完成的工作,我相信您想要更多类似的东西:

I believe you want something more like this, if I've correctly understood what you were trying to accomplish:

RewriteEngine On

RewriteCond %{REQUEST_URI} !=/events/index.html
RewriteCond %{REQUEST_URI} !=/calendar/index.html
RewriteCond %{REQUEST_URI} !=/info/faq.html
RewriteRule ^.*$ http://mynewsite.com/$0 [R=301,L]

Redirect 301 /info/faq.html http://mynewsite.com/my-page

这篇关于htaccess 301重定向整个站点,但有例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆