nonwww to www WITH redirect using .htaccess rewrite rule

时间:2016-12-24 11:31:04

标签: php apache .htaccess mod-rewrite

我需要将没有www的所有请求重定向到www,但我还需要每个重定向都以index.php结束

.htaccess文件代码

RewriteEngine On
RewriteBase /
RewriteRule ^(_part) - [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php?/$0 [PT,L]

当前网址:  http://example.com

预期网址:http://www.example.com

拜托,有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

您可以使用:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

RewriteRule ^(_part) - [F,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php?/$0 [PT,L]