How to make website accessible with and without "www"

1

My site is only accessing without the "www" inside the directory of my site, has a .htaccess with this rule:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdominio\.meusite\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.subdominio\meusite\.com$
RewriteRule ^(.*)$ "http\:\/\/subdominio\meusite\.com\.br/$1" [R=301,L]

I use CentoS and Apache. Do I have to see any Rewrite module stop if it is active or inactive on my server? How do I do this?

And another problem is that my pages are only being accessed with the extension at the end: .php, .html etc. How can I fix this too?

    
asked by anonymous 27.09.2015 / 08:54

1 answer

2

For the extensions problem check the apache conf file of the dir_module parameter, if you do not add the following lines:

<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

Restart apache and test, this allows the index.html or index.php files in the root folder of the site within the apache to be automatically opened for the user Ex: what was previously accessed with www.meusite.com.br/index.php can now be accessed with www.meusite.com.br , the names index.html and index.php are commonly used by default (if it is not standard for your case add the file name of the root directory of the apache server you want to open).

When your site's access needs to contain www at the start you will need to create a DNS entry, if you use Bind as your DNS server you should have the zone for your site created, it's fine likely to have something like this on your DNS server.

zone "meusite.com.br" {
        type master;
        file "/etc/namedb/remote/meusite.com.br.zone";
};

Go to the file meusite.com.br.zone and create the www entry for your site:

www            IN      A       XXX.XX.XX.XX (IP publico do seu servidor web)

If this IP already has a registered name which usually happens, create a CNAME entry, increment the DNS conf file serial number and restart the DNS service so that its DNS entry can propagate around the world.

    
27.09.2015 / 16:21