htaccess 301 轉址

利用mod_rewrite功能修改如下:

1
2
3
4
5
6
7
8
9
10
11
# 以下兩行不可省略
Options +FollowSymLinks
RewriteEngine on

# 將index.php 轉到 /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]

# 將沒有www 轉到有 www
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]