Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

[Impossible?] How do you redirect non-www to www? 
 
skjerfdeg.no
Sr. Member
 
Avatar
Total Posts:  104
Joined:  2008-09-08
Norway
 

I would like to redirect my url: http://domain.no to http://www.domain.no. This seems to be impossible. If I use a standard redirect in my .htaccess file it seems to work but as soon as I try to open a link on my page it will not longer work. If I remove the url forwarding it all goes back to working…

Is it possible to get this working? I loose a lot of SEO with this!

 
Magento Community Magento Community
Magento Community
Magento Community
 
tzyganu
Mentor
 
Avatar
Total Posts:  2205
Joined:  2009-11-18
Bucharest, Romania
 

try adding this to your httpd.conf file on the server or the .htaccess file

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

RewriteCond     %{HTTPS} on
RewriteCond   
%{HTTP_HOST}   !^www\.(.*)$   [NC]
RewriteRule   
^(.*)$   https://www.%{HTTP_HOST}$1  [R=301,L]
 
Magento Community Magento Community
Magento Community
Magento Community
 
skippybosco
Enthusiast
 
Avatar
Total Posts:  796
Joined:  2008-10-03
 

Also be sure to check your Magento configuration.

Logged on to admin -> System Configuration -> Web

Check Unsecure and Secure paths

 
Magento Community Magento Community
Magento Community
Magento Community
 
skjerfdeg.no
Sr. Member
 
Avatar
Total Posts:  104
Joined:  2008-09-08
Norway
 

Thanks, it now seems to work!

Changing the .htaccess file did not do the trick, i still couldnt navigate on the homepage after editing. But when changing the settings under web, changed from skjerfdeg.no to http://www.skjerfdeg.no its possible to navigate on the site also after performing a redirect.

Thanks guys smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
itsrashad
Jr. Member
 
Total Posts:  1
Joined:  2013-02-16
 
skippybosco - 28 March 2010 10:11 PM

Also be sure to check your Magento configuration.

Logged on to admin -> System Configuration -> Web

Check Unsecure and Secure paths

Thanks, I fix my problem by this way. Again Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
adamoh
Jr. Member
 
Total Posts:  1
Joined:  2012-06-27
 

I had the same issue, and here is how I solved it:

add the following to index.php:

switch($_SERVER['HTTP_HOST']{
    
case 'site2.com':
    case 
'site2.com':
        
$mageRunCode 'site2code';
        
$mageRunType 'website';
    break;
    case 
'www.site2.com':
    case 
'www.site2.com':
        
$mageRunCode 'site2code';
        
$mageRunType 'website';
    break;

    case 
'www.site1.com':
    case 
'www.site1.com':
        
$mageRunCode 'base';
        
$mageRunType 'website';
    break;
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
ibo_s
Jr. Member
 
Total Posts:  8
Joined:  2011-11-18
 

Hey,

for me the htaccess way from tzyganu did it.

But the redirects should look like this:

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

Otherwise the slash is missing and URLs like website.com/foo.html are redirected to http://www.website.comfoo.html instead of http://www.website.com/foo.html.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top