Reputation: 207
I want to temporary redirect my site from www to non-www. for example if anyone type the url
http://www.example.com should be redirects to http://example.com
http://www.example.com/page -> http://example.com/page
So, for this i have used the following code in my .htaccess file
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
but anyhow it is not working and also my rewrite module is active on my server. Please anyone suggest me how i can temporary redirect for www to non-www site.
Thanks for advance!
UPDATED
I got the issue guys. It is some mis-configuration issue on hosting domain for www record.
Previously it is mis-configured so thats why www.example.com is an unknown host and it was not pointing to my hosted files and .htaccess file is not calling when i call my domain with www.example.com
Thanks Guys for your meaning full suggestions :)
Upvotes: 1
Views: 135
Reputation: 41219
Your code is working fine on my server. Clear your browser cache and you will be fine.
To temp redirect from www to non www, you need to remove the 301 part from the R flag, 301 represents Permanent Redirect
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R,L]
Upvotes: 1