.htaccess 301 重定向仅适用于 1 个新链接
我有一个带有重定向 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>
只有第二个重定向有效,带有 get 方法的文件没有重定向,我做错了吗?
编辑:
这是我的整个模组重写:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^index\.php$ / [R=301,L]
RewriteRule ^(.*)/index\.php$ /$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [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
I have .htaccess file with redirect 301 on it and placed right under the rewriteengine
<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>
only 2nd redirect works, the one with the get method are not redirected, am i doing wrong?
EDITED :
this is my entire mod rewrite :
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^index\.php$ / [R=301,L]
RewriteRule ^(.*)/index\.php$ /$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
混合使用
RewriteRule
和Redirect 301
指令通常不是一个好主意。他们可能会以意想不到的方式相互冲突。您依赖于RewriteRule
,因此您应该使用更多的重定向来实现重定向。Redirect 301
无法根据 URL 中的查询字符串 (?...
) 进行重定向,因此您无论如何都需要为该重定向实现 RewriteRules。当您有重定向特定 URL 的规则时,它们应该位于
.htaccess
文件的顶部,以便它们优先于其他更通用的规则。我建议禁用目录索引,因为我担心它会与您的
RewriteRule ^index\.php$ / [R=301,L]
规则冲突。我在您的
.htaccess
文件中没有看到RewriteEngine On
,尽管您发布的开头代码片段中有它。尝试将此作为您的
.htaccess
:It is usually not a good idea to mix
RewriteRule
andRedirect 301
directives. They can conflict with each other in unexpected ways. You depend ofRewriteRule
so you should implement your redirects with more of them.Redirect 301
can't redirect based on query strings (?...
) in the URL, so you need to implement RewriteRules for that redirect anyway.When you have rules for redirecting specific URLs, they should go at the top of the
.htaccess
file so that they take precedence over the other more general rules.I would recommend disabling the directory index because I fear it would conflict with your
RewriteRule ^index\.php$ / [R=301,L]
rule.I don't see
RewriteEngine On
in your.htaccess
file, despite that your snippet you posted to start with has it.Try this as your
.htaccess
: