1. Knowledge Base
  2. >
  3. Advanced Troubleshooting
  4. >
  5. Default files .htaccess and php.ini

Default files .htaccess and php.ini

Note: If the .htaccess file is coded incorrectly, it can cause website errors. Please keep in mind that HostGator does not provide direct support regarding the coding of .htaccess files. This resource is for informational purposes only.

Before you make changes to your .htaccess file, we strongly recommend creating a full backup of your files. For additional information on how to generate a full backup, please refer to the following article:

The .htaccess file is a special Apache file that you can use to manipulate the behavior of your site. These manipulations include things such as redirects that force all of your domain's pages to https or www. You can even redirect all users to one page, while your IP loads another page. Default .htaccess files for common CMS scripts are also included in the event you need to restore the file back to the default code.

For additional information on .htaccess files please refer to the following article:


CMS Default .htaccess Files

In the event you need to restore the default .htaccess file for a specific CMS script, such as WordPress or Joomla, you can use the code provided within this section to directly copy into your .htaccess file.

Click any button to pop up a box containing .htaccess code.


php.ini Files

You can declare changes to PHP within in this file and update specific settings by manipulating variable values. For additional information regarding the php.ini file, please refer to the following article:

The following articles contain the full text of the php.ini files for the most recent versions of PHP available on our servers:


.htaccess Redirects and Rewrites

Redirect and Rewrite methods within the .htaccess file include, but are not limited to, forcing www and https, as well as implementing page specific redirects.

The code provided within this section may need to be modified to use your domain name or cPanel username. This code is not directly supported by HostGator and is for informational purposes only.
Disable Trace Method
Trace is enabled by default for debugging purposes. However, if you are not actively utilizing this function it is recommended that it is disabled for security purposes. Please select the button above for the .htaccess code needed to disable this request method.
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
Directory Index Redirect
This .htaccess directive will allow you to specify the file which loads as your default page. Please select the button above for the .htaccess code needed to accomplish this redirect method.
#Change index.html to whatever filename you want to load when the domain is typed in without a filename
DirectoryIndex index.html
Force WWW:
This .htaccess code will allow you to force your domain to load www when accessed. Please select the button above for the .htaccess code needed to accomplish this rewrite method.
# Replace domain.com with the real domain name
# This example is for redirecting whatever domain to the same domain with www. on the front
# Swap domain.com and www.domain.com between the 2 lines to have it do the reverse

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

# Replace altdomain.com and domain.com with the real domain name
# This example is for making a pseudo park, making some addon domain appear as the primary, etc
# As above, swap altdomain.com and domain.com between the 3 lines to have it do the reverse

RewriteCond %{HTTP_HOST} ^altdomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.altdomain.com$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

# For those that care, the $1 at the end will make sure that all links on the site work and appear as the domain.com instead of as the altdomain.com


RewriteEngine On 
RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteRule ^(.*) http://www.%{HTTP_HOST}/$1 [R=301,QSA,L]
Force https
This .htaccess code will allow you to force your domain to load https:// when accessed. Please select the button above for the .htaccess code needed to accomplish this rewrite method.
RewriteEngine On

RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L]
Redirect all users except for specified IPs
This .htaccess code will allow you to force all users (excluding the IP address included in the code) to be redirected to a specific page when they access your domain. Please select the button above for the .htaccess code needed to accomplish this redirect method.
#Redirects all users to page.html except specified IP

RewriteEngine On
RewriteCond %{REMOTE_ADDR} !216.110.94.227 #Replace with actual IP address.
RewriteRule .* page.html [NC] #Replace with file name.
Redirect phpbb File Type to php
This .htaccess code will allow you to redirect phpbb files, often used with registration forms, to php URLs. This method is often used with Google Analytics so you can track entries of the registration form easily. Please select the button above for the .htaccess code needed to accomplish this redirect method.
# This will allow you to set your phpbb registration forms to look like register.php the aup agreement page to be reg_agreed.php
# and the reg success page to be thankyou.php and it will send the information entered on the various forms to the proper pages ..
# This is handy for Google Analytics, as you can set that to track the entry to the registration form to register.php,
# and then the registration complete through thankyou.php


RewriteRule ^register.php?(.*)$ http://forums.domain.com/ucp.php?mode=register&$1&%{QUERY_STRING} [L]
RewriteRule ^reg_agreed.php?(.*)$ http://forums.domain.com/ucp.php?mode=register&$1&%{QUERY_STRING} [L]
RewriteRule ^thankyou.php?(.*)$ http://forums.domain.com/ucp.php?mode=register&$1&%{QUERY_STRING} [L].
Redirect to a Subdirectory
This .htaccess code will allow you to redirect your domain to a subdirectory. Please select the button above for the .htaccess code needed to accomplish this redirect method.
RewriteEngine On
Options +FollowSymlinks
RewriteBase /


RewriteCond %{HTTP_HOST} ^.*$
RewriteCond %{REQUEST_URI} !subfolder/
RewriteRule ^(.*)$ subdfolder/$1 [L]
Custom Error Pages
This .htaccess code will allow you to redirect your domain's Error Pages to a custom error page. Please select the button above for the .htaccess code needed to accomplish this redirect method
# Get whichever line applies to the error code you want to use. Make sure to replace the .html file on the right
# with the real filename you want to be your error page

ErrorDocument 400 /400.html
ErrorDocument 401 /403.html
ErrorDocument 403 /403.html
ErrorDocument 404 /404.html
ErrorDocument 500 /500.html
Lightweight Error Pages
This .htaccess code will allow you to redirect your domain's Error Pages to a lightweight custom error page. This method is typically used in periods of high traffic or in the event of a DDoS attack to preserve resources. Please select the button above for the .htaccess code needed to accomplish this redirect method.
# Get whichever line applies to the error page you want to use. 

ErrorDocument 401 "HTTP 401: Access Denied"
ErrorDocument 403 "HTTP 403: Forbidden"
ErrorDocument 404 "HTTP 404: Object not found"

Handler Example Codes

A PHP handler defines the method of communication between the Apache web server and your PHP Scripts. This includes handling HTML pages as PHP and executing Perl scripts.

Note: It is no longer necessary to manually create handler statements to change the PHP version for a directory. For additional instructions regarding this process please refer to the following article:
Execute Perl
This example will instruct the Apache web server to execute Perl scripts ending in .pl as CGI.
## Make sure you set the .pl or .cgi file to 755 permissions
## Make sure you also replace .pl with the extension of the file you are using (.cgi .html if that is what it is, etc)

Options +ExecCGI

AddHandler cgi-script .pl
Process .html as .php
This example will instruct the Apache web server to execute PHP in .html files.
AddHandler application/x-httpd-php5 .php .html