martingeorgiu
martingeorgiu

Reputation: 44

nonwww to www WITH redirect using .htaccess rewrite rule

I need to redirect all request without www to www, but I also need to every redirect will end on index.php

.htaccess file code

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

Current url : http://example.com

Expected url: http://www.example.com

Please,anyone can help me?

Upvotes: 0

Views: 73

Answers (1)

Croises
Croises

Reputation: 18671

You can use:

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]

Upvotes: 1

Related Questions