繁体   English   中英

重定向301代码停止工作

[英]Redirect 301 code stopped working

我需要一些帮助来弄清楚为什么我的代码不再起作用。

原主题: 如何通过一个查询重定向多个相似的URL?

请参阅原始问题。

似乎代码已停止为我工作。 很长一段时间都很好,现在正在导致错误。 我有以下代码:

RedirectMatch 301 ^/([^-]+)-([^-]+)-([^-]{2})\.html$ /$1-in-$2-$3.html
RedirectMatch 301 ^/([^-]+)-([^-]+)-([^-]+)-([^-]{2})\.html$ /$1-$2-in-$3-$4.html

我想要的网址切换:

domain.com/music-classes-dallas-tx.htmldomain.com/music-classes-in-dallas-tx.html

有谁知道为什么这可能会停止工作? 我可以进行哪些更改以使其再次运行?

更新:由于文件名的差异,此方法不正确。 请参阅下面的评论。


使用mod_rewrite ,可以在.htaccess文件中使用以下命令:

RewriteEngine on

# Condition: First, check that `-in-` is not contained in the request URI
RewriteCond %{REQUEST_URI} !-in- [NC]

# Rule: If it isn't, redirect the old page to the new one
RewriteRule ^([a-z-]+)-([a-z]+)-([a-z]{2})\.html$ /$1-in-$2-$3.html [NC,L,R=301]

如果您还希望确保重定向到的文件确实存在,则可以在上面指定的条件下添加此文件:

RewriteCond %{REQUEST_FILENAME} -f

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM