我有 .htaccess 檔案,上面有重定向 301,并放在 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>
只有第二個重定向有效,帶有 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
uj5u.com熱心網友回復:
RewriteRule混合和Redirect 301指令通常不是一個好主意。它們可能以意想不到的方式相互沖突。你依賴,RewriteRule所以你應該用更多的重定向來實作你的重定向。
Redirect 301無法基于?...URL 中的查詢字串 ( ) 進行重定向,因此無論如何您都需要為該重定向實作 RewriteRules。
當您有重定向特定 URL 的規則時,它們應該放在.htaccess檔案的頂部,以便它們優先于其他更一般的規則。
我建議禁用目錄索引,因為我擔心它會與您的RewriteRule ^index\.php$ / [R=301,L]規則沖突。
我沒有RewriteEngine On在您的.htaccess檔案中看到,盡管您發布的代碼片段有它。
試試這個作為你的.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]
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/441227.html
標籤:.htaccess 重定向 http-status-code-301 规范链接 规范化
下一篇:無法打開子目錄laravel安裝
