簡體   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