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.
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
#Change index.html to whatever filename you want to load when the domain is typed in without a filename
DirectoryIndex index.html
# 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]
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L]
#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.
# 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].
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} ^.*$
RewriteCond %{REQUEST_URI} !subfolder/
RewriteRule ^(.*)$ subdfolder/$1 [L]
# 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
# 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.
## 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
AddHandler application/x-httpd-php5 .php .html