.htaccess rewrite - http:// to http://www
I am new to .htaccess redirection.
I am using the below code
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc]
But when i hit the URL http://example.com/folder/file.php i'm getting redirected to http://www.example.com/file.php which is开发者_JAVA百科 wrong.
Can someone please help me with this
Help is greatly apreciated
Thanks
Alright can you try this in your .htaccess or apache conf file:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
There are some typos and some unescaped characters, but most important you're missing a needed "$" character in that *rewritecond %{http_host} ^example.com [nc]* line.
Here is your code "as it should have been":
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,NC]
Though, I personally use and would recommend doing it like this:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^!www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,NC]
That should get you going... ;)
精彩评论