How to use .htaccess to run all .html files as .php by using PHP handlers in Apache w/o CGI?

If you are not able to find the correct Handler, Simply create a .php file with the following contents: <?php echo $_SERVER['REDIRECT_HANDLER']; ?> and run/open this file in browser. example application handler Use this output in .htaccess file Create a .htaccess file at the root of your website(usually a folder named public_html or htdocs on linux servers) and add this line: AddType [[THE OUTPUT FROM ABOVE FILE]] .html .htm Example ...

January 23, 2019 · 1 min · Harshvardhan Malpani

Fix Error Too Many Redirects on WordPress Admin page or Blog

There are several cases for the cause and multiple solutions also: 1 Add these 2 lines in wp-config.php file if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) $_SERVER['HTTPS']='on'; 2 Edit these settings in database directly using PhpMyAdmin in table options or wp_options in option_id, option_name (1,siteurl) and (2,home) wp_options table 3 You can do the same by Editing wp-config.php and adding these 2 lines define('WP_HOME','https://example.com'); define('WP_SITEURL','https://example.com'); 4 Fix your .htaccess file with default one Check here for default .htaccess for wordpress

December 27, 2018 · 1 min · Harshvardhan Malpani

Common PHP.ini directives list for Apache htaccess files

Maximum Execution Time and Maximum Input Time php_value max_execution_time 300 php_value max_input_time 300 Max Upload file size and Max POST data size php_value upload_max_filesize 20M php_value post_max_size 21M Output buffering toggle php_value output_buffering on # OR php_value output_buffering 16384 Expose PHP signature – toggle php_value expose_php on Maximum Input variables php_value max_input_vars 1500 Maximum Memory Limit for PHP php_value memory_limit 1256M Magic Quotes toggle php_value magic_quotes_gpc on Register Global Variables – useless now ...

October 30, 2018 · 1 min · Harshvardhan Malpani

Default .htaccess file for wordpress with compression and caching tweaks

Here is the default .htaccess file for wordpress If you are using cpanel, before you proceed make sure that you don’t have htaccess file already. Default File Manager settings in cpanel make it hidden Default Settings in cPanel File Manager .htaccess file – default code for wordpress # BEGIN WordPress <ifmodule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </ifmodule> # END WordPress If your WordPress Installation is inside a directory say knowledge, which means your wordpress url is https://abcd.com/knowledge/ then htaccess code would be ...

October 9, 2018 · 2 min · Harshvardhan Malpani

.htaccess redirect from http to https and from non-www to www redirect – Make site permanently SSL secured

put this in your htaccess file: RewriteCond %{HTTP_HOST} !^www\.(.*) RewriteRule (.*) https://www.%{HTTP_HOST}/$1 [R=301,L] RewriteCond %{HTTPS} !=on RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

July 27, 2018 · 1 min · Harshvardhan Malpani

Forcing website to https and www using htaccess on apache servers

To first force HTTPS, you must check the correct environment variable %{HTTPS} off, but your rule above then prepends the www. Since you have a second rule to enforce www., don’t use it in the first rule. RewriteCond %{HTTPS} off # First rewrite to HTTPS: # Don't put www. here. If it is already there it will be included, if not # the subsequent rule will catch it. RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] # Now, rewrite any request to the wrong domain to use www. # [NC] is a case-insensitive match RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

February 21, 2018 · 1 min · Harshvardhan Malpani

CORS policy for subdomains – htaccess – apache server

Works for Magento 2.2x Cross-Origin Resource Sharing header for Access-Control-Allow-Origin for Subdomains SetEnvIf Origin "^(.*\.yourdomain\.com)$" OSD=$1 Header set Access-Control-Allow-Origin "%{OSD}e" env=OSD Header set Access-Control-Allow-Methods: "*" Header set Access-Control-Allow-Headers: "*" or a general format for simple copy paste: SetEnvIf Origin "^(.*)$" OSD=$1 Header set Access-Control-Allow-Origin "%{OSD}e" env=OSD Header set Access-Control-Allow-Methods: "*" Header set Access-Control-Allow-Headers: "*"

December 20, 2017 · 1 min · Harshvardhan Malpani

How to secure a folder by whitelisting one IP using HTACCESS and denying all others

The process involves matching all requests for an IP, if the IP does not match redirect all secured directory requests. RewriteCond %{REMOTE_ADDR} !^120\.120\.120\.120 RewriteRule ^admin/.* - [L,R=403] RewriteCond %{REMOTE_ADDR} ^120\.120\.120\.120 RewriteRule ^admin$ - [L,R=403] If you want to control this IP using a script, you can add 2 lines ###CUSTOM RULES### # your rules will appear here using php script ###CUSTOM RULES### Now add a script, say happy.php and use the following code: ...

October 26, 2017 · 1 min · Harshvardhan Malpani