htaccess 301 重定向整个网站,但有例外

发布于 2024-09-12 20:56:03 字数 315 浏览 4 评论 0原文

我正在尝试创建一个 htaccess 文件来重定向我的整个网站(除了一些例外),但我无法让它工作。我需要重定向整个内容,提供特定的重定向,并排除两个页面。以下是我的非工作示例。谢谢!

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

救赎№ 2024-09-19 20:56:03

您尝试将 mod_rewritemod_alias 混合使用,但 RewriteCond 语句无法调节 Redirect 语句,因为它们不是来自同一个模块。

如果我正确理解了您想要实现的目标,我相信您想要更多类似的东西:

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

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
熊抱啵儿 2024-09-19 20:56:03

我有类似的问题。尝试重定向整个域(robots.txt 文件除外)。蒂姆的回答对我不起作用,但这确实有效

RewriteEngine On
RewriteRule robots.txt - [L]
RewriteRule ^.*$ http://www.newsite.com/$0 [R=301,L]

I had a similar issue. Trying to redirect an entire domain with the exception of its robots.txt file. Tim's answer didn't work for me, but this did

RewriteEngine On
RewriteRule robots.txt - [L]
RewriteRule ^.*$ http://www.newsite.com/$0 [R=301,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文