jon
jon

Reputation: 1581

rewrite htaccess to include www and include rest of url

The following code reditrects the user to www, if the www is missing in the url, however how do you redrirect to the same url just including www

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

Eg the above redirects:

mydomain.com/goHere/

to

www.mydomain.com

but I would like it to redirect to

www.mydomain.com/goHere/

Thanks in advance to any responders. J

Upvotes: 2

Views: 137

Answers (1)

anubhava
anubhava

Reputation: 785631

Try this code:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI}  [R=301,L]

Make sure to test this in a different browser or clear your browser cache.

Upvotes: 2

Related Questions