Replying to my Original Issue posted QaziSalmanAhmad and the Server and requirement details in this post QaziSalmanAhmad , I'm now posting my own Solution here now which has achieved the required result.
Guys I have figured the solution out for this Issue on Apache Server running on Linux Redhat shared hosting server. Here I'm posting my solution so it might help other with the same and/or similar issues on Apache Server.
The Requirement
I personally wanted to set my flarum site URL to http://helptanks.com/ in config.php file and handle the redirection via the .htaccess file of every request with www prefix like http://www.helptanks.com/ to be redirected. This way I wanted to handle the original issue I posted initially.
The Solution:
After the active, responsive and always willing to help community members here pointed me in right direction.
I started to search for a way to configure the redirection properly via .htaccess file on a shared server running Apache. Because on a shared server, access to the Apache's .conf files is restricted.
So inside .htaccess file, I just added:
# ########################################################
# Redirect from (www.YOUR-DOMAIN.com) to (YOUR-DOMAIN.com)
RewriteCond %{HTTP_HOST} ^www.helptanks.com [NC]
RewriteRule ^(.*)$ http://helptanks.com/$1 [L,R=301]
#
## Can be set as follows to reverse the above redirection.
# Redirect from (YOUR-DOMAIN.com) to (www.YOUR-DOMAIN.com)
#
## Uncomment the 2 lines just below to reverse the setting
###RewriteCond %{HTTP_HOST} ^helptanks.com [NC]
###RewriteRule ^(.*)$ http://www.helptanks.com/$1 [L,R=301]
after the start of
<IfModule mod_rewrite.c>
RewriteEngine on
Here's the solution that is working for me now:
# Allow access if Flarum is installed in a subdirectory,
# but another .htaccess in a higher directory denies access.
<IfModule mod_authz_core.c>
Require all granted
</IfModule>
<IfModule !mod_authz_core.c>
Order Allow,Deny
Allow from all
</IfModule>
# Fix for https://httpoxy.org vulnerability
Header unset Proxy
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteRule ^vendor/(.*)?$ / [F,L]
RewriteRule ^storage/(.*)?$ / [F,L]
RewriteRule ^config.php$ / [F,L]
RewriteRule ^.git/(.*)?$ / [F,L]
RewriteRule ^api(.*)$ api.php [QSA,L]
RewriteRule ^admin(.*)$ admin.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !^assets index.php [QSA,L]
# ########################################################
# Redirect from (www.YOUR-DOMAIN.com) to (YOUR-DOMAIN.com)
RewriteCond %{HTTP_HOST} ^www.helptanks.com [NC]
RewriteRule ^(.*)$ http://helptanks.com/$1 [L,R=301]
#
## Can be set as follows to reverse the above redirection.
# Redirect from (YOUR-DOMAIN.com) to (www.YOUR-DOMAIN.com)
#
## Uncomment the 2 lines just below to reverse the setting
###RewriteCond %{HTTP_HOST} ^helptanks.com [NC]
###RewriteRule ^(.*)$ http://www.helptanks.com/$1 [L,R=301]
# MultiViews can mess up our rewriting scheme
Options -MultiViews
# Autoindex will list all assets files which is not so good
Options -Indexes
</IfModule>
<IfModule mod_deflate.c>
# Compress all output labeled with one of the following MIME-types
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE application/atom+xml \
application/javascript \
application/json \
application/vnd.ms-fontobject \
application/x-font-ttf \
application/x-web-app-manifest+json \
application/xhtml+xml \
application/xml \
font/opentype \
image/svg+xml \
image/x-icon \
text/css \
text/html \
text/plain \
text/xml
</IfModule>
</IfModule>
# Configure cache expiry for different file types
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 1 second"
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/json "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType text/xml "access plus 0 seconds"
ExpiresByType image/x-icon "access plus 1 week"
ExpiresByType text/html "access plus 0 seconds"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType application/x-web-app-manifest+json "access plus 0 seconds"
ExpiresByType text/cache-manifest "access plus 0 seconds"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType application/atom+xml "access plus 1 hour"
ExpiresByType application/rss+xml "access plus 1 hour"
ExpiresByType application/font-woff2 "access plus 1 month"
ExpiresByType application/font-woff "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
ExpiresByType application/x-font-ttf "access plus 1 month"
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
</IfModule>
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php56” package as the default “PHP” programming language.
<IfModule mime_module>
AddType application/x-httpd-ea-php56 .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
# BEGIN cPanel-generated php ini directives, do not edit
# Manual editing of this file may result in unexpected behavior.
# To make changes to this file, use the cPanel MultiPHP INI Editor (Home >> Software >> MultiPHP INI Editor)
# For more information, read our documentation (https://go.cpanel.net/EA4ModifyINI)
<IfModule php5_module>
php_flag display_errors On
php_value allow_url_fopen On
php_value max_execution_time 30
php_value max_input_time 60
php_value max_input_vars 1000
php_value memory_limit 128M
php_value post_max_size 8M
php_value session.gc_maxlifetime 1440
php_value session.save_path "/var/cpanel/php/sessions/ea-php56"
php_value upload_max_filesize 3M
php_flag zlib.output_compression Off
</IfModule>
# END cPanel-generated php ini directives, do not edit
Found this solution on this page: https://www.interserver.net/tips/kb/redirect-domain-com-to-www-domain-com-vice-versa/ - thanks to the author Jithin on http://interserver.net.
It explains the steps in a pretty straight-forward way.
Another good resource for reference is http://www.htaccess-guide.com/
@luceos Please mark it Solved.
Thanks to every participant for their answers.