Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 重定向301代码已停止工作_Html_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

Html 重定向301代码已停止工作

Html 重定向301代码已停止工作,html,.htaccess,mod-rewrite,redirect,Html,.htaccess,Mod Rewrite,Redirect,我需要一些帮助来找出我的代码不再工作的原因 原始线程: 请看原问题 似乎代码对我已经不起作用了。这在很长一段时间内都很好,但现在却导致了错误。我有以下代码: RedirectMatch 301 ^/([^-]+)-([^-]+)-([^-]{2})\.html$ /$1-in-$2-$3.html RedirectMatch 301 ^/([^-]+)-([^-]+)-([^-]+)-([^-]{2})\.html$ /$1-$2-in-$3-$4.html URL开关我想要: domain

我需要一些帮助来找出我的代码不再工作的原因

原始线程:

请看原问题

似乎代码对我已经不起作用了。这在很长一段时间内都很好,但现在却导致了错误。我有以下代码:

RedirectMatch 301 ^/([^-]+)-([^-]+)-([^-]{2})\.html$ /$1-in-$2-$3.html
RedirectMatch 301 ^/([^-]+)-([^-]+)-([^-]+)-([^-]{2})\.html$ /$1-$2-in-$3-$4.html
URL开关我想要:

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


有人知道为什么这会停止工作吗?我可以更改什么使其再次工作?

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


使用,您可以在
.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

你试过使用吗?抱歉,我的帖子中的原始线程链接错误。我已经更新了。原文:迈克,我还没试过。我不确定它会是什么样子。介意分享代码吗?我可以试一试吗?谢谢迈克!不幸的是,它似乎没有重定向。我的链接是:domain.com/music-classes-death-valley-ca.html。。。它不会让我移动到domain.com/music-classes-in-death-valley-ca.htmlIt应该是。测试在我这边起作用。您的
.htaccess
文件中还有其他内容吗?我发现我的方法不正确。。。问题是一些路径将具有
something tx
,而其他路径将具有
something tx
。因此,很难确定-中的
-in应该放在哪里。。。话虽如此,我认为您最好还是坚持使用旧的URI模式,特别是因为像
中的
这样的关键字(据我所知)不被搜索引擎识别。谢谢您的尝试。奇怪的是,以前的方法是有效的。我将很快粘贴我的htaccess。以下是我的.htaccess中以前工作过的代码:
#在RewriteBase/RewriteRule^index\.php$-[L]RewriteCond%{REQUEST_FILENAME}-f RewriteCond%{REQUEST_FILENAME}-重写规则/index.php[L]#END WordPress RedirectMatch 301^/([^-]+)-([^-]+)-([^-]+)-([^-]+)-([^-]+)-([^-]+)-([^-]+)\.html$/$1-$2-in-$3.html