![](/img/trans.png)
[英].htaccess, <Directory />, gives Internal Server Error, 500
[英]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 個)參數,因此這些規則永遠不會匹配。
其他小問題:
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.