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.

ab_ files eating space in Temp folder

fonte: http://consek-blog.azurewebsites.net/cab_-files-eating-space/

cab_ files eating space in Temp folder

Two days ago one of my coworker called me, because he couldn’t start one of our proprietary applications. I got to him prepared to “reinstall” the program. I deleted the program folder and tried to paste working one from my backup and BAM!, no sufficient disk space box appeared. I thought “WTF?”.

I quickly returned to My Computer and noticed that there were 0 (sic!) bytes  free on C drive. I knew that this would be a very interesting case to investigate, so I switched the laptop with spare one and took it to my office. 🙂

The first thing I did was to run TreeSize (you can find it in Tools) which gave me this nice overview of disk usage:

cab_ files eating space int Temp folder 01

As you can see C:WindowsTemp takes up 173,7 GB of space! I decided to check that folder and saw this:cab_ files eating space int Temp folder 02

The folder was filled with hundreds of cab_ files!

From the dates I deducted that, on average, almost every hour 5 files were created. This was happening every working day, for the last nine months! No wonder they grew up so large.

I decided to check what what was creating them. I deleted all unused files from Temp (for nicer view 🙂 ) and set up Procmon with filter set to “Path begins with C:WindowsTempc”. All I had to do was to wait for my prey 🙂

Luckily I didn’t have to wait for long, as first files were created in 5 minutes.

cab_ files eating space int Temp folder 06

I checked Procmon and got:

cab_ files eating space int Temp folder 03

It turned out that a simple compressing program was causing all the trouble. But why was that?

You can see that in the “Command Line:” box we have a file supplied as a parameter to the program. So lets check it.

When I got to C:WindowsLogsCBS I stumped upon a CBS.log, a couple of CBSPersist_%date%.cab and some CBSPersist_%date%.txt. (Sorry for no screen shots but I forgot to make them, so you’ll have to believe me 🙂 ). All the .cab and .txt files looked like old logs, so why not all of them are .cabs? I checked the .txt with the earliest modification date and I got my answer… It was 5GB in size! So now let me give you a little background information about what is happening here.


How does makecab work?

Makecab creates a compressed cab archive from selected file. To do this it creates cab_%numbers% file in Temp folder (if you run it from normal account it uses user’s temp folder). After everything is completed all the files are deleted. And why it didn’t happen here? Because the txt file it tried to compress was too big for it to handle:

cab_ files eating space int Temp folder 07

Here you have shown what happened when I tried to manually compress the txt file. The program exited before deleting the temporary files.


But why it grew up so large? To find the cause, let’s check what program started makecab in the first place.

To do this we will use Parent PID from makecab’s procmon event properties, and Task Manager with shown PID column:

cab_ files eating space int Temp folder 12

Now we have the bad guy! But what are his motives?

By using Procmon, Procexp and some google-fu I learned that TrustedInstaller is used by Windows Update to perform updates, which explains periodicity of file creation. When WU check for updates, TrustedInstaller writes a lot of information in CBS.log file. TI is also responsible for starting the process of compressing the log when it grows too large (50-500MB). It does it by renaming the original log to CBSPersist_%currentdate%.txt (below you have the renaming process captured in Procmon), and then calling makecab program with proper parameters.

cab_ files eating space int Temp folder 10

By looking at the modification dates on .txt files I noticed that the problematic file must have grown that large in only 4 days (last .cab had modification date set to 10.10.14r and .txt had 14.10.14r.). Why TrustedInstaller didn’t prevent it? Well, the only reasonable explanation for me is that WU wasn’t checking for updates during that time so there was no log size control.

And here things got interesting… When WU won’t check for updates? Only when there are ones waiting for restart, to install themselves! Sadly System Log was set to overwrite old log entries rather than archive, so I don’t have any proof of my diagnose, but I think that after installing updates no one restarted the laptop for 4 days. It was the first week we had this laptop in our production environment, so surely he had a lot of information to write there. One thing that supports it is that on my home system I saw a 0.5GB CBS.log file and it was only one day old 🙂

I think that this fully solves the problem and explains everything in detail 🙂

Thanks for reading, and remember to restart your computer once in a while 🙂 To the next time!

Allow DNS Suffix Appending to Unqualified Multi-Label Name Queries

fonte: http://www.computerstepbystep.com/allow-dns-suffix-appending-to-unqualified-multi-label-name-queries.html

Description:

Specifies whether the computers to which this setting is applied may attach suffixes to an unqualified
multi-label name before sending subsequent DNS queries, if the original name query fails.

A name containing dots, but not dot-terminated, is called an unqualified multi-label name, for example
“server.corp”. A fully qualified name would have a terminating dot, for example “server.corp.contoso.com.”.

If you enable this setting, suffixes are allowed to be appended to an unqualified multi-label name, if the
original name query fails. For example, an unqualified multi-label name query for “server.corp” will be queried
by the DNS Client first. If the query succeeds, the response is returned to the client. If the query fails, the
unqualified multi-label name is appended with DNS Suffixes configured for the computer for queries. These
suffixes can be derived from a combination of the local DNS Client’s primary domain suffix, a
connection-specific domain suffix and/or DNS Suffix Search List.

For example, if the local DNS Client receives a query for “server.corp”, and a primary domain suffix is
configured as “contoso.com”, with this setting the DNS Client will send a query for “server.corp.contoso.com.”
if the original name query for “server.corp” fails.

If you disable this setting, no suffixes are appended to unqualified multi-label name queries if the original
name query fails.

If you do not configure this setting, computers will use their local DNS Client configuration to determine the
query behavior for unqualified multi-label names.

Supported on: At least Windows Vista.
Allow DNS Suffix Appending to Unqualified
Multi-Label Name Queries

DescriptionGpeditRegeditCMDBack

VBScriptPowerShell Script

Gpedit:

Please perform the following steps:

Please go to Pearl button (Start) and click on the Search programs and files
For more information about the change from Start to Pearl button click here

Type gpedit.msc and press Enter

In the Group Policy window please navigate to Computer Configuration> Administrative Templates>
Network > DNS Client and open Allow DNS Suffix Appending to Unqualified Multi-Label Name Queries.
Not Configured > is the Default state
Enabled> apply this GPO
Disabled> this GPO will not be applied

To finish press ok button and close Group Policy window.

DescriptionGpeditRegeditCMDUpBack

VBScript

Type regedit and press ok

Please confirm User Account Control pop-up

Microsoft official disclaimer

Warning Serious problems might occur if you modify the registry incorrectly by using Registry Editor or by
using another method. These problems might require that you reinstall the operating system. Microsoft
cannot guarantee that these problems can be solved. Modify the registry at your own risk.

Note: This registry key is created by Group Policy when this GPO is Enable or Disable. The GPO Default state
is Not Configured> this registry entry is not present.

Please navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows NT\DNSClient and
locate
AppendToMultiLabelName registry key
Regedit:          

Please perform the following steps:

Please go to Pearl button (Start) and click on the Search programs and files
For more information about the change from Start to Pearl button click here

DescriptionGpeditRegeditCMDUpBack

VBScript

Double click on AppendToMultiLabelName and edit the value:

To Enable:
Change the data value with 1

To Disable:
Change the data value with 0

To finish press ok button and close Registry Editor window

Note: Manual editing of this registry key will not be reflected in Group Policy. If you modify this GPO from
Group Policy this registry key will be rewritten.

DescriptionGpeditRegeditBackCMD

VBScriptUp

Type cmd, right click on cmd icon under the Programs and click on Run as administrator

Please confirm User Account Control pop-up

Please select, right and copy a registry key from below, then right click on command prompt window
, select Paste and press Enter

Enabled:
REG add “HKLM\SOFTWARE\Policies\Microsoft\Windows NT\DNSClient” /v AppendToMultiLabelName /t REG_DWORD /d 1 /f

Disabled:
REG add “HKLM\SOFTWARE\Policies\Microsoft\Windows NT\DNSClient” /v AppendToMultiLabelName /t REG_DWORD /d 0 /f

Not Configured:
REG DELETE “HKLM\SOFTWARE\Policies\Microsoft\Windows NT\DNSClient” /v AppendToMultiLabelName /f

Note: Manual editing of this registry key will not be reflected in Group Policy. If you modify this GPO from
Group Policy this registry key will be rewritten.
CMD:

Please perform the following steps:

Please go to Pearl button (Start) and click on the Search programs and files
For more information about the change from Start to Pearl button click here

DescriptionGpeditRegeditBackCMD

VBScriptUp

VBScript:

Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = “.”
Set oReg=GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” & _
strComputer & “\root\default:StdRegProv”)

strKeyPath = “SOFTWARE\Policies\Microsoft\Windows NT\DNSClient”
oReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath
strValueName = “AppendToMultiLabelName”
‘Enabled
dwValue = 1
‘Disabled
‘dwValue = 0
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
‘Not Configured
‘oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName

DescriptionGpeditRegeditBackCMD

VBScriptUp

PowerShell Script :

Enabled\Disabled

$RegKey = “HKLM:\SOFTWARE\Policies\Microsoft”
If(Test-Path ($RegKey + “\Windows NT”))
{
 $RegKey = “HKLM:\SOFTWARE\Policies\Microsoft\Windows NT”
 If(Test-Path ($RegKey + “\DNSClient”))
 {
   $RegKey = “HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\DNSClient”
   ##Enabled
   New-ItemProperty –path $RegKey –name AppendToMultiLabelName –value 1 –PropertyType DWord –Force
   ##Disabled
   ##New-ItemProperty –path $RegKey –name AppendToMultiLabelName –value 0 –PropertyType DWord –Force
 }
 else
 {
   New-Item –path $RegKey –name Service
   $RegKey = “HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\DNSClient”
   ##Enabled
   New-ItemProperty –path $RegKey –name AppendToMultiLabelName –value 1 –PropertyType DWord
   ##Disabled
   ##New-ItemProperty –path $RegKey –name AppendToMultiLabelName –value 0 –PropertyType DWord
 }
}
else
{
 New-Item –path $RegKey –name Windows NT
 $RegKey = “HKLM:\SOFTWARE\Policies\Microsoft\Windows NT”
 New-Item –path $RegKey –name Service
 $RegKey = “HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\DNSClient”
 ##Enabled
 New-ItemProperty –path $RegKey –name AppendToMultiLabelName –value 1 –PropertyType DWord
 ##Disabled
 ##New-ItemProperty –path $RegKey –name AppendToMultiLabelName –value 0 –PropertyType DWord
}

Not Configured

$RegKey = “HKLM:\SOFTWARE\Policies\Microsoft”
Remove-ItemProperty –Path($RegKey + “\Windows NT\DNSClient”) –name AppendToMultiLabelName
If( (Get-Item –Path($RegKey + “\Windows NT\DNSClient”)).ValueCount –eq 0 –and (Get-Item –Path($RegKey + “\Windows NT\DNSClient”)).SubKeyCount –eq 0)
{
 Remove-Item –Path($RegKey + “\Windows NT\DNSClient”)
 If( (Get-Item –Path($RegKey + “\Windows NT”)).ValueCount –eq 0 –and (Get-Item –Path($RegKey + “\Windows NT”)).SubKeyCount –eq 0)
 {
   Remove-Item –Path($RegKey + “\Windows NT”)
 }
}