简体   繁体   English

htaccess 文件格式在某些重定向上会出现内部服务器错误

[英]htaccess file format gives internal server error on some redirects

I have a .htaccess file with the following content;我有一个 .htaccess 文件,内容如下;

My .htaccess file:我的 .htaccess 文件:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^/?$ https://meervoormamas.nl [R=301,L]
RewriteRule ^/dossiers/autisme/?$ https://meervoormamas.nl/kind/ontwikkeling/ R=301,L]
RewriteRule ^/schoolkind/opvoeding/7\-tips\-om\-uw\-kinderen\-te\-begeleiden\-op\-sociale\-netwerken/?$ https://meervoormamas.nl/kind/opvoeding/7-tips-om-uw-kinderen-te-begeleiden-op-sociale-netwerken/ R=301,L]
</IfModule>

Where the first RewriteRule does work, if I type in https://mamalove.nl it redirects to https://meervoormamas.nl But with the second RewriteRule(a category in WP) gives an Internal server error, and also with the third RewriteRule (a post).第一个 RewriteRule 确实有效的地方,如果我输入https://mamalove.nl它会重定向到https://meervoormamas.nl但是使用第二个 RewriteRule(WP 中的一个类别)会给出内部服务器错误,并且还有第三个重写规则(一篇文章)。

What am I doing wrong?我究竟做错了什么?

As well as the missing opening [ that delimits the flags (3rd) argument on the RewriteRule directive, as mentioned in comments, in a directory ( .htaccess ) context the URL-path matched by the RewriteRule pattern does not start with a slash, so these rules will never match.正如评论中提到的那样,在目录.htaccess )上下文中,与RewriteRule模式匹配的 URL 路径不以斜杠开头,因此除了缺少的开头[分隔RewriteRule指令上的标志(第 3 个)参数,因此这些规则永远不会匹配。

Other minor issues:其他小问题:

  • You are missing the trailing slash after the domain in the first rule's substitution string.您在第一条规则的替换字符串中缺少域后的斜杠。
  • No need to backslash-escape literal hyphens when used outside of a regex character class (3rd rule).在正则表达式字符 class (第三条规则)之外使用时,无需反斜杠转义文字连字符。
  • The RewriteBase directive is not being used here.此处未使用RewriteBase指令。
  • The <IfModule> wrapper is not required. <IfModule>包装器不是必需的。

Try the following instead:请尝试以下操作:

RewriteEngine On

RewriteRule ^$ https://meervoormamas.nl/ [R=301,L]
RewriteRule ^dossiers/autisme/?$ https://meervoormamas.nl/kind/ontwikkeling/ [R=301,L]
RewriteRule ^schoolkind/opvoeding/7-tips-om-uw-kinderen-te-begeleiden-op-sociale-netwerken/?$ https://meervoormamas.nl/kind/opvoeding/7-tips-om-uw-kinderen-te-begeleiden-op-sociale-netwerken/ [R=301,L]

Since you appear to be redirecting to a similar URL-path in the 3rd rule, this can be "simplified" by avoiding repetition.由于您似乎在第三条规则中重定向到类似的 URL 路径,因此可以通过避免重复来“简化”。 For example:例如:

RewriteRule ^school(kind/opvoeding/7-tips-om-uw-kinderen-te-begeleiden-op-sociale-netwerken)/?$ https://meervoormamas.nl/$1/ [R=301,L]

$1 is a backreference that contains everything in the captured group in the preceding pattern . $1是一个反向引用,包含前面模式中捕获的组中的所有内容。 It basically just removes the "school" prefix and ensures the redirected URL ends in a trailing slash.它基本上只是删除了“学校”前缀并确保重定向的 URL 以斜杠结尾。

If these rules are being used on an existing WordPress site then these directives must go at the top of the .htaccess file, before the # BEGIN WordPress section. If these rules are being used on an existing WordPress site then these directives must go at the top of the .htaccess file, before the # BEGIN WordPress section.

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

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