.htaccess 301 重定向仅适用于 1 个新 link

.htaccess 301 redirect only work for 1 new link

我有带有重定向 301 的 .htaccess 文件,并放在重写引擎下面

<IfModule mod_rewrite.c>
RewriteEngine On
#now this is the redirect
Redirect 301 /blog.php?slug=konsolidasi-tanah-frequently-asked-questions https://jpi.or.id/blog/2021/02/11/pengertian-konsolidasi-tanah

Redirect 301 /blog/2021/02/11/konsolidasi-tanah-frequently-asked-questions https://jpi.or.id/blog/2021/02/11/pengertian-konsolidasi-tanah

</IfModule>

只有第 2 次重定向有效,使用 get 方法的重定向不会重定向,我做错了吗?

已编辑:

这是我的整个 mod 重写:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ .php
RewriteRule ^index\.php$ / [R=301,L]
RewriteRule ^(.*)/index\.php$ // [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/ [L]
# Permanent URL redirect
Redirect 301 /blog.php?slug=konsolidasi-tanah-frequently-asked-questions https://jpi.or.id/blog/2021/02/11/pengertian-konsolidasi-tanah
# Permanent URL redirect
Redirect 301 /blog/2021/02/11/konsolidasi-tanah-frequently-asked-questions https://jpi.or.id/blog/2021/02/11/pengertian-konsolidasi-tanah

Redirect 301 /blog.php?slug=konsolidasi-tanah-frequently-asked-questions /blog/2021/02/11/pengertian-konsolidasi-tanah
RewriteRule ^blog/2021/02/11/pengertian-konsolidasi-tanah   /blog.php?slug=konsolidasi-tanah-frequently-asked-questions

混合使用 RewriteRuleRedirect 301 指令通常不是一个好主意。它们会以意想不到的方式相互冲突。您依赖于 RewriteRule,因此您应该使用更多的重定向来实现。

Redirect 301 无法根据 URL 中的查询字符串 (?...) 进行重定向,因此无论如何您都需要为该重定向实施 RewriteRules。

当您有重定向特定 URL 的规则时,它们应该放在 .htaccess 文件的顶部,以便它们优先于其他更通用的规则。

我建议禁用目录索引,因为我担心它会与您的 RewriteRule ^index\.php$ / [R=301,L] 规则冲突。

我在你的 .htaccess 文件中没有看到 RewriteEngine On,尽管你发布的开头片段中有它。

试试这个作为你的 .htaccess:

# Disable index.html, index.php default functionality
DirectoryIndex disabled

RewriteEngine On

# Permanent URL redirect
RewriteCond %{QUERY_STRING} ^slug=konsolidasi-tanah-frequently-asked-questions$
RewriteRule ^blog\.php$ https://jpi.or.id/blog/2021/02/11/pengertian-konsolidasi-tanah [R=301,L]

RewriteRule ^blog/2021/02/11/konsolidasi-tanah-frequently-asked-questions$ https://jpi.or.id/blog/2021/02/11/pengertian-konsolidasi-tanah  [R=301,L]

# Forward URLs without .php extension to existing PHP file
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ .php

# Redirect index.php URLs to the directory
RewriteRule ^index\.php$ / [R=301,L]
RewriteRule ^(.*)/index\.php$ // [R=301,L]

# Use index.php as a front controller
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/ [L]