舊網址:
1. https://example.com/images/1/image1.png
2. https://example.com/images/2/image2.png
3. https://example.com/images/3/image9.jpg
4. https://example.com/images/4/image19.jpg
新網址:
1. https://example.com/images/101.png
2. https://example.com/images/202.png
3. https://example.com/images/309.jpg
4. https://example.com/images/419.jpg
規則:
- 檔案夾“ 1 ” “ 0 ” “ 1.png ”
- 檔案夾“ 2 ” “ 0 ” “ 2.png ”
- 檔案夾“ 3 ” “ 0 ” “ 9.jpg ”
- 檔案夾“ 4 ” “ 19.jpg ”
現在我有了 .htaccess 的代碼:
RewriteEngine On
# Rewrite HTTP to HTTPS
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R=301,L]
# Rewrite index.php to /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
RewriteRule ^index\.php$ / [R=301,L]
# Rewrite Query/ to Query
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (. )/$ /$1 [R=301,L]
RewriteRule ^24$ / [R=301,L]
# Rewrite Query to index.php?route=Query
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?route=$1 [QSA,L]
uj5u.com熱心網友回復:
在該RewriteEngine On行之后立即嘗試以下操作:
RewriteRule ^images/(\d )/image(\d)\.(png|jpg)$ /images/$10$2.$3 [R=301,L]
RewriteRule ^images/(\d )/image(\d{2,})\.(png|jpg)$ /images/$1$2.$3 [R=301,L]
第一條規則處理包含單個數字(必須以 為前綴0)的影像名稱,第二條規則處理其余部分。
的$1,$2和$3反向參考在前面的匹配相應的捕獲子組RewriteRule 圖案。換句話說,$1包含檔案夾名稱(所有數字),$2包含出現在檔案名之后的數字并$3包含檔案擴展名(jpg或png)。
注意:首先使用 302(臨時)重定向進行測驗,以避免潛在的快取問題。
澄清一下,大概您已經在內部鏈接到新的影像 URL?
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/409921.html
標籤:
