【问题标题】:.htaccess redirect not directing to specified file.htaccess 重定向不重定向到特定文件
【发布时间】:2018-09-12 16:39:21
【问题描述】:

我的旧域上有一个 .htaccess 文件,其中包含未按我想要的重定向的重定向。

如果我输入 olddomain.com/about-us.html,重定向会将用户发送到 newdomain.com/about-us.html。我想要做的是将用户引导至 newdomain.com/about。

下面是我的 .htaccess 文件,其中包含一个重定向示例。

有人看到我做错了吗?

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteCond %{THE_REQUEST} !/administrator [NC]

RewriteRule /about-us.html https://newdomain.com/about [L,R=301]

Redirect 301 /about-us.html  https://newdomain.com/about


RewriteRule ^ https://newdomain.com%{REQUEST_URI} [L,R=301,NE]

网络标签:

【问题讨论】:

  • @anubhava 是的,我确实清除了它。
  • @anubhava 检查我在我的问题中的编辑。我发布了它的图片。

标签: .htaccess redirect


【解决方案1】:

像这样:

RewriteEngine On

RewriteRule ^about-us\.html$ https://newdomain.com/about [L,R=301,NC]

RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteCond %{THE_REQUEST} !/administrator [NC]
RewriteRule ^ https://newdomain.com%{REQUEST_URI} [L,R=301,NE]
  • 确保在新浏览器中测试或完全清除浏览器缓存。
  • 测试时确保 .htaccess 中没有其他代码

【讨论】:

  • 谢谢!这行得通。对于子文件夹中更深的文件,我会这样做吗? RewriteRule /about-us/employees\.html$
  • 不要使用前导斜杠。所以使用:RewriteRule ^about-us/employees\.html$ /something [L,R=301,NC]
  • 我做错了吗?此特定行不起作用。我尝试了不同的浏览器。 RewriteRule ^about-us/t-slotted-aluminum-profiles\.html$ https://newdomain.com/profile [L,R=301,NC]
  • 你的规则最后匹配.html,所以你的源URL应该是:https://mbkitsystems.com/about-us/t-slotted-aluminum-profiles.html
  • 完美。谢谢大家的帮助!非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-26
  • 1970-01-01
  • 2012-01-24
  • 2014-11-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多