Setting up a permanent 301 redirect via .htaccess

fonte:http://www.inmotionhosting.com/support/website/redirects/setting-up-a-301-permanent-redirect-via-htaccess

A permanent 301 redirect in your .htaccess file lets search engines and others know that an old link has been replaced by a new one. It’s the recommended method for directing traffic from an existing page.

Some common uses of a 301 .htaccess redirect:

You have the ability to setup redirects for a domain in your cPanel interface one link at a time. You can also add the redirects manually by modifying your .htaccess file directly.

Getting to your .htaccess file

On a Linux server you would use your .htaccess file to implement a 301 redirect for your pages.

  • Login to your cPanel.
  • Under Files, click on File Manager.
  • Select the Document Root for: option, and choose your domain from the drop-down.
  • Ensure that Show Hidden Files is selected.
  • Then click Go.
file-manager-hidden-files
  • Right-click on the .htaccess file and select Edit.
file-manager-htaccess-edit
  • If your .htaccess file didn’t exist already during the previous step, click on New File at the top-left, name the file .htaccess, and finally set the directory for the file to be created to /public_html/ or the document root of your site.
file-manager-htaccess-create
  1. You might have a text editor encoding dialog box pop-up, you can simply click on Edit.

Redirect individual files

To redirect individual files, like example.com/oldfile.htm to newfile.htm you can use a 301 redirect like this:

Redirect 301 /oldfile.htm /newfile.htm

single file 301 redirect

To redirect one specific file to another domain such as example.com/oldfile.htm to example.net/newfile.htm:

Redirect 301 /oldfile.htm http://example.net/newfile.htm

single file domain 301 redirect

Redirect an old domain to a new domain

If you had an old domain such as example.com, and now you decided you actually want to use example.net for the website. You could setup a 301 redirect for the entire domain, so that old links to example.com carry over.

Code in the example.com domain’s .htaccess file:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.net/$1 [L,R=301,NC]

full domain 301 redirect

Force www. version of domain to be used

A search engine like Google would see example.com and www.example.com as essentially two separate websites. They recommend you pick one version you’d like search engines to display and using a 301 redirect is a possible option.

If you have a lot of links on the web where people are linking to your site as example.com, but you would like your visitors to instead end up at www.example.com you can force this version of your domain with these rules:

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

force www 301 redirect

Force non www. version of domain to be used

If you have a lot of links on the web where people are linking to your site as www.example.com, but you would like your visitors to instead end up at example.com you can force this version of your domain with these rules:

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

force non www 301 redirect

Redirect all files with certain extension

To re-direct all of one type of file to another, such as example.com/file.php to example.com/file.htm

RewriteEngine On
RewriteCond %{REQUEST_URI} .php$
RewriteRule ^(.*).php$ /$1.htm [R=301,L]

file extension 301 redirect

You should now know how to properly setup 301 permanent redirects on your website to help ensure that search engines and visitors coming to your site from older links can still get to your new content.

How to Setup a Domain Redirect in cPanel

fonte: http://www.inmotionhosting.com/support/edu/cpanel/cpanel-manage-domains/redirect-domain

At times you may want to redirect traffic from one domain to another domain. This can be done at the domain level or for specific web pages. For example, domain.com and it’s web traffic can be redirected to anotherdomain.com OR domain.com/aboutus.html can be redirected to anotherdomain.com/about.html. In this guide we will show you how to create a redirect in your cPanel. This automatically adds a redirect rule to your .htaccess file for you.

Redirecting a Domain

    1. Login to cPanel.
    2. Click the Redirects button in the Domains section.
    3. You will then be on the Add Redirect page. Click the drop-down box for Type and choose if you want to create a Permanent (301), or Temporary (302) redirect.
    4. Click the next drop-down box and choose the domain you want to redirect.
    5. For the slash ‘/’ field enter any folder names if necessary.
    6. Enter the address you want to redirect to in the Redirects to section.
    7. Choose if you want to “Only redirect with www.” “Redirect with or without www.” or “Do Not Redirect www.
    8. Check the box if you want to create a Wild Card Redirect. This will add the the file/folder name after the url when it redirect. For instance, example.com/test.php would redirect to example2.com/test.php.
    9. Click the Add button when you are finished.


You are finished when you see a green message with the details of your redirect.

Congratulations, now you know how to create a redirect in your cPanel! You can also create a 301 redirect directly in your .htaccess file.

Hosting Multiple Domains In Tomcat

fonte: http://iam-rakesh.blogspot.it/2009/10/hosting-multiple-domains-in-tomcat.html

Hosting Multiple Domains In Tomcat

Tomcat allows us to host multiple domains in one instance, using multiple ‘Host‘ tags. In this article I will explain how to do it on Tomcat. This is very simple configuration using ‘Host‘ tags in your server.xml. A novice can also understand this configuration very easily.
Before going into the details of the configuration first lets have a look at the ‘Host‘ tag, ‘Context‘ tag and ‘Alias‘ tags first.

   <Host name="domain1" appBase="[application base]" autoDeploy="[true/false]" 
        unpackWARs="[true/false]">
    <Alias>...</Alias>
    <Context path="" docBase="" reloadable="[true/false]"/>
   </Host>
First lets have a look at ‘Alias‘ tag. This tag is used to provide aliases for your actual domain. For example you have a domain called ‘domain1.com’, and you want to run the same application for ‘www.domain1.com’ also, then you can use this ‘Alias’ tag to provide an alias name for the actual domain.

   <Host name="domain1.com" ...>
    <Alias>www.domain1.com</Alias>
    <Alias>domain1.net</Alias>
    <Alias>www.domain1.net</Alias>
    ...
   </Host>

As you can see in the above example, if you want to have multiple aliases you can add multiple ‘Alias’ tags for each domain alias name.
Now lets move on to the ‘Context‘ tag. The ‘Context’ element represents a web application running inside a host. To explain this in an easy way; each directory under ‘webapps’ directory of your tomcat is one context. Manager and Admin consoles of your tomcat installation are two different contexts running under your ‘localhost’ domain.

   <Context path="" docBase="" reloadable="[true/false]"/>

In the above code snippet I’ve provided minimum configuration needed for a context. Lets go through the attributes of ‘Context’ tag.
path‘ attribute – here we need to give the relative URL [to the host URL in which this Context is being configured] of the context. Say you want to run the application from “domain.com/beta” then the ‘path’ attribute needs to be “/beta”.
docBase‘ – the Document Base directory. Here we need to give the root directory for this context. This can be an absolute path to the directory/WAR file OR relative to the ‘appBase’ given in the ‘Host’ tag. If the context root directory is inside the ‘appBase’ directory of the ‘Host’ tag then we can give it as

   docBase="."

reloadable‘, it defaults to ‘false’. If you give ‘true’ to this value, tomcat looks for changes in the ‘WEB-INF/classes’ or ‘WEB-INF/lib’ directory and reloads the context automatically. This will useful in development environment, so that a new deployment doesn’t result restarting tomcat. But on production server its better to leave the default value as setting it to true results an overhead on the server.
Now the ‘Host‘ tag – it represents a host [also called as Virtual Host] running, associated with a domain name in the server. We can have multiple ‘Host’ tags to host multiple domains in one tomcat. Lets see the attributes.

   <Host name="domain1" appBase="[application base]" autoDeploy="[true/false]" 
        unpackWARs="[true/false]">
   ...
   <Host/>

name‘ – Domain Name attribute. Here we need to give the domain name which you are trying to host/deploy.
appBase‘ – Application Base Directory attribute. Here we need to give the root directory for this application which contains web applications to be deployed on this host. It can be either an absolute path to the directory OR relative to the ‘CATALINA_BASE’ directory.
autoDeploy‘ – flag to denote newly placed web applications should be deployed automatically. If this attribute is set to true and you place a WAR file OR a Web application directory in ‘appBase’ then tomcat automatically deploys the application.
unpackWARs‘ – if set to true Tomcat will automatically unpack the WAR files placed in to corresponding directory structure.
Now lets look at the configuration to host multiple domains.

   <Engine defaultHost="domain1.com" name="Catalina">
    <Host name="domain1.com" appBase="/home/user1/domain1">
     <Alias>www.domain1.com</Alias>
     <Context path="" docBase="."/>
    </Host>
    <Host name="domain2.com" appBase="/home/user1/domain2">
     <Alias>www.domain2.com</Alias>
     <Context path="" docBase="."/>
    </Host>
    <Host name="domain3.com" appBase="/home/user1/domain3">
     <Alias>www.domain2.com</Alias>
     <Context path="" docBase="."/>
    </Host>
   </Engine>

In the above configuration we tried to host three domains in Tomcat. We added three ‘Host’ tags one for each domain we wanted to host. Each domain points to a different [‘appBase’] directory [I used absolute paths for ‘appBase’ attribute, it can be relative to CATALINA_BASE].
That’s it for now!