繁体   English   中英

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

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

我有一个 .htaccess 文件,内容如下;

我的 .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>

第一个 RewriteRule 确实有效的地方,如果我输入https://mamalove.nl它会重定向到https://meervoormamas.nl但是使用第二个 RewriteRule(WP 中的一个类别)会给出内部服务器错误,并且还有第三个重写规则(一篇文章)。

我究竟做错了什么?

正如评论中提到的那样,在目录.htaccess )上下文中,与RewriteRule模式匹配的 URL 路径不以斜杠开头,因此除了缺少的开头[分隔RewriteRule指令上的标志(第 3 个)参数,因此这些规则永远不会匹配。

其他小问题:

  • 您在第一条规则的替换字符串中缺少域后的斜杠。
  • 在正则表达式字符 class (第三条规则)之外使用时,无需反斜杠转义文字连字符。
  • 此处未使用RewriteBase指令。
  • <IfModule>包装器不是必需的。

请尝试以下操作:

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]

由于您似乎在第三条规则中重定向到类似的 URL 路径,因此可以通过避免重复来“简化”。 例如:

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

$1是一个反向引用,包含前面模式中捕获的组中的所有内容。 它基本上只是删除了“学校”前缀并确保重定向的 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.

暂无
暂无

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

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