繁体   English   中英

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

[英].htaccess 301 redirect only work for 1 new link

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

<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

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

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

当您有重定向特定 URL 的规则时,它们应该位于 .htaccess 文件顶部的.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 ^(.*)$ $1.php

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

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

暂无
暂无

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

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