htaccess - redirect sang category mới

htaccess - redirect sang category mới

  • Giả sử bạn thay đổi tên category, thì tất cả các trang bên trong category sẽ thay đổi đường dẫn theo tên mới, việc cần làm khi này là redirect tất cả đường dẫn category cũ sang category mới, ta làm như sau:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^folder1/(.*)$ https://hocwebchuan.com/folder2/$1 [R=301,L]
  • Việc làm trên sẽ thay đổi đường dẫn tất cả các file bên trong folder1 sang folder2, ví dụ từ https://hocwebchuan.com/folder1/item.php sang https://hocwebchuan.com/folder2/item.php

htaccess - redirect đường dẫn vào một cấp thư mục

  • Ví dụ ta thay đổi đường dẫn từ /item.php sang /product/item.php, ta làm như sau:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} example.com$ [NC]
RewriteCond %{HTTP_HOST} !product
RewriteRule ^(.*)$ http://hocwebchuan.com/product/$1 [R=301,L]
  • RewriteCond %{HTTP_HOST} example.com$ [NC] xác định domain, không phân biệt chữ hoa hay thường.
  • RewriteCond %{HTTP_HOST} !product lọc điều kiện không thuộc thư mục product.
  • RewriteRule ^(.*)$ http://hocwebchuan.com/product/$1 [R=301,L] thực hiện redirect vào bên trong thư mục product.