Một số cách tạo redirect

Để redirect từ dạng http://domain.com sang http://domain.com/folder hoặc http://domainnew.com có khá nhiều cách, ở đây xin giới thiệu với các bạn một vài cách đơn giản để làm việc này:
Một số cách tạo redirect
1. Dùng file index.php

Các bạn tạo file index.php đặt vào thư mục bạn muốn redirect sang trang khác, ví dụ muốn redirect từ http://domain.com sang http://domain.com/folder thì các bạn đặt file index.php vào thư mục public_html, nội dung file index.php như sau:

<?php
error_reporting(0);

header( 'refresh: 0; url=http://domain.com/folder/' );

die();

?>

2. Dùng file .htaccess

Các bạn tạo file .htaccess với nội dung sau và đặt vào thư mục public_html:

RewriteEngine on

RewriteCond %{REQUEST_URI} ^\/$ [NC]

RewriteRule ^.*$ "\/folder\/" [R=301,L]