Friday, March 2, 2018

How To Change Default Server Timezone Via Htaccess File

Change server timezone via htaccess

If you create a website using a CMS like Joomla, you will have a file named htaccess.txt in the installation result. In the web hosting server, .htaccess.txt is in the root directory of your primary domain that is public_html where the Joomla files and folders are in it. According to the Joomla documentation, for the sake of the Joomla SEO, you need to convert htaccess.txt to .htaccess. Many people will think that .htaccess is one of the file extensions because it uses a dot (.) at the beginning but .htaccess is indeed the name of a file.

In the web servers that run the Apache web server software, .htaccess is a configuration file. .htaccess can be used to change the Apache Web Server configuration such as enabling or disabling its features and functionality. In the Apache document root, this file will be detected and executed by Apache web server software. By default, the file names started with a dot (.) in Apache web server are hidden files. To show these files, you need to enable the Show Hidden Files feature in cPanel.

.htaccess has many functions such as redirecting URL, denying visitor by IP address or referrer, password protection, preventing access to the php.ini file, and so forth. In addition to these functions, another function of .htaccess is to set server timezone, and this article is about it. The server has specific timing and follows its physical location. If the server location is overseas, for example, in Singapore, the server time will use Asia/Singapore time. If the website uses a server in Singapore while it is intended for visitors in America, the time shown on the website becomes inaccurate.

To solve this issue, you can use .htaccess to change the default time zone and then show the time from the local time zone. If you do not have .htaccess, you can create it using a text editor like Notepad. In addition to .htaccess, changing the server time zone can also be done via the php.ini file. But for shared hosting, access to php.ini is restricted. If you want to change the default timezone of the server via .htaccess, here are the steps:

Log in first to your cPanel account, in the Files group, click or choose File Manager. On the File Manager page, make sure you are in the root directory by clicking the public_html directory (1), select the .htaccess file (2), and then clicking the Edit button (3).

Change server timezone via htaccess

In the Edit dialog box that pops up, click the Edit button. .htaccess is open in the editor. Now it is the time for you to specify the local time zone you want to use. If you are unsure of the name or timezone format, you can check it here. This example will use America time zone.

Change server timezone via htaccess

After you select the Asian time zone, you then select another more specific Asia time zone, such as Asia / Jakarta timezone.

Change server timezone via htaccess

To change the default server time zone with the local time zone, add the code below at the top line of the .htaccess file, click the Save button to save the changes, and then click Close button closes the currently active page.

# Change the default time zone
SetEnv TZ America/Los_Angeles

Change server timezone via htaccess