301 redirects work to www.example.com but not for

I am getting a weird 301 code redirect issue that the code with www in the link works with and doesn't work without www

RewriteBase /
RewriteRule ^api$ http://example.com/topic/api [R=301,L]

      

if i type http://www.example.com/api it works but if i do http://example.com/api it doesn't work

Help thanks Prasanth

+2


source to share


1 answer


Check your virtual host setting should be below

<VirtualHost *:80>
  ...
  ServerName www.example.com
  ServerAlias example.com
  ...
</VirtualHost>

      



If the page is not found, it is possible that example.com and www.example.com point to a diff directory, otherwise example.com cannot be linked to anywhere.

0


source







All Articles