[英].htaccess: Redirect 301 conflict with rewriterule
我最近更新了一個舊網站,我希望將所有舊頁面301添加到每個舊版本的新版本中。
這是我的.htaccess
Options +FollowSymlinks -MultiViews
RewriteEngine On
#
# below are the 301 redirects
# **rules**
#
# below are the RewriteCond
# **rules**
#
# other stuff
#
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+?)/?$ $1.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ /$1 [R=301,L]
問題是,某些舊鏈接的擴展名為oldfile.html
,其他鏈接只是文件夾oldfolder/
。
在新版本上有products
, products/category
和products/category/subcategory
。 這些網址是使用RewriteCond
生成的。
以下規則有效:
Redirect 301 /category/ /products/category
以下不起作用,而是將我重定向到主頁。
Redirect 301 /old-folder/subcategory.html /products/category/subcategory
# /products/category/subcategory is also a RewriteRule
這是.htaccess
的確切代碼
# 301 rule
Redirect 301 /arredo-urbano/blocchi-standard.html /prodotti/arredo-urbano/001-blocchi-standard
# RewriteRule
RewriteRule ^prodotti/([^/]+)/([^/]+)/?$ prodotti.php?category=$1&subcategory=$2 [L]
我嘗試在每個Redirect 301
之后添加[L]
標志,以便忽略.htaccess的其余部分,但這會導致500 Internal Error
所有重定向都是手動聲明的,沒有正則表達式或通配符,並且它們都拼寫正確。
有沒有辦法讓所有重定向工作按預期進行? 另外我不明白的是[L]
標志導致內部錯誤的原因。
謝謝
關於重定向規則的三條建議:
Redirect
(mod_alias)規則與RewriteRule
(mod_rewrite)規則混合使用。 在你的.htaccess中試試這些規則:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteRule ^category/?$ /products/category [L,NC,R=301]
RewriteRule ^old-folder/subcategory\.html$ /products/category/subcategory [L,NC,R=301]
#
# below are the 301 redirects
# **rules**
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ /$1 [R=301,L]
#
# below are the RewriteCond
# **rules**
#
# other stuff
#
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
在測試此更改之前,請務必清除瀏覽器緩存。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.