Ways to block user via .htaccess

#Order deny,allow #Deny from all #Allow from 3.92.40.40 #Allow from 4.30.3.0/4 #Allow from 4.30.3.18 #Allow from 4.30.3.15 #Allow from 104.9.55.44 RewriteCond %{REMOTE_ADDR} !^(4\.30\.3\.[0-9]*)$ RewriteCond %{HTTP:X-Forwarded-For} !^(4\.30\.3\.[0-9]*)$ RewriteCond %{REMOTE_ADDR} !^(104\.9\.55\.44)$ RewriteCond %{HTTP:X-Forwarded-For} !^(104\.9\.55\.44)$ RewriteRule ^(.*) - [F]

December 9, 2021 · 1 min · Harshvardhan Malpani

How to fix Magento2 apis not working? fix coupon apis and other PUT OPTIONS APIs

The issue is actually related to your server’s configuration. By default all types of requests are not allowed. Please add the following to your .htaccess file <Limit GET POST OPTIONS PUT DELETE PROPFIND> Order allow,deny Allow from all Require all granted </Limit>

September 26, 2021 · 1 min · Harshvardhan Malpani

How to put a site in maintenance? [Apache web server]

ErrorDocument 403 /index.html DirectoryIndex index.html <Files ~ "index\.html"> Order Allow,Deny Allow from all </Files> Deny from all Content of your .htaccess file If you want to whitelist any IP, use this ErrorDocument 403 /index.html DirectoryIndex index.html <Files ~ "index\.html"> Order Allow,Deny Allow from all </Files> Order Allow,Deny Allow from xx.xxx.xx.xx Deny from all Here is a sample htaccess for a wordpress website with 1 IP whitelisted 4.129.45.44 and all others are banned. So you only will be able to load the website while everyone else will see contents of index.html with HTTP Status code 403 ...

September 8, 2021 · 1 min · Harshvardhan Malpani

Basic Authentication in nginx for any domain, server or location block

sudo yum install httpd-tools sudo htpasswd -c /etc/nginx/conf.d/vhosts/.htpasswd USERNAME Enter Password: xxxxx sudo chmod 644 /etc/nginx/conf.d/vhosts/.htpasswd Update the domain.conf file like /etc/nginx/conf.d/vhosts/myrestricteddomain.com.ssl.conf Ideally, use it in server config 1 2 3 4 5 server { satisfy all; auth_basic "Restricted Area"; auth_basic_user_file /etc/nginx/conf.d/vhosts/.htpasswd; location / { Save and restart nginx

August 3, 2021 · 1 min · Harshvardhan Malpani

Basic Authentication with Nginx with proxy port (react/node app etc)

Reference:https://docs.nginx.com/nginx/admin-guide/security-controls/configuring-http-basic-authentication/ Requirements: apache2-utils or httpd-tools Use htpasswd utility and create a .htpasswd file, see reference\ htpasswd -c /etc/nginx/.htpasswd usernamethatyouwant chmod 644 /etc/nginx/.htpasswd After that, just add lines in nginx conf 1 2 3 4 5 6 7 8 9 10 location / { auth_basic "Backend Area"; auth_basic_user_file /etc/nginx/.htpasswd; ## path to your passwd file ## ... ## xyz code ##... proxy_pass http://127.0.0.1:4000; ## Proxy port for your app proxy_set_header Authorization ""; ## DONT FORGET THIS. reset the auth header include proxy.inc; } Restart nginx now or test first using “nginx -t”

January 22, 2021 · 1 min · Harshvardhan Malpani

Sample .htaccess for Laravel with PHP FPM

SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1 # RewriteEngine On # RewriteCond %{HTTP:Authorization} ^(Bearer\ )(.*)$ [NC] # RewriteRule ^(.*) $1?access_token=%2 [QSA] #Header set Access-Control-Allow-Origin "*" #Header set Access-Control-Allow-Methods "GET,PUT,POST,DELETE" #Header set Access-Control-Allow-Headers "Content-Type, Authorization" <IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://kprep.api.ozandac.com/$1 [R,L] RewriteEngine On # Prevent direct access to the "public" folder - redirect to root RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /public/ RewriteRule ^public/(.*) /$1 [R=302,L] # Redirect Trailing Slashes If Not A Folder... # - but look for the file in the "public" folder # (ensure we are not already in the "public" folder) RewriteCond %{REQUEST_URI} !^/public/ RewriteCond %{DOCUMENT_ROOT}/public/$1 !-d RewriteRule ^(.*)/$ /$1 [R=302,L] # Rewrite "everything" to the "public" subdirectory if not already # This ignores existing files/dirs in the document root RewriteCond %{REQUEST_URI} ^/(.*) RewriteRule !^public/ public/%1 # Handle Front Controller... (as before) RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] </IfModule>

October 23, 2020 · 1 min · Harshvardhan Malpani

How to whitelist IPs in NGINX configuration?

Add this code in your .conf file if ($remote_addr = "14.51.20.3") { set $block_me_now "B"; } if ($remote_addr = "104.1.20.29") { set $block_me_now "B"; } if ($block_me_now != "B") { return 403; break; }

June 8, 2020 · 1 min · Harshvardhan Malpani

How to fix Undefined class constant ‘ARRAY_AS_PROPS’ Fatal Error?

I received this error “Fatal Error: Uncaught error in Undefined class constant ‘ARRAY_AS_PROPS’” This issue is not related to PHP if you have 7.0 and above, it is zend framework’s module zend-http wrapper which is affected if Apache module is not present File responsible: zendframework\zend-http\src\Header\Cookie.php:75 73 74 75 76 public function __construct(array $array = []) { parent::__construct($array, ArrayObject::ARRAY_AS_PROPS); } Solution Do check enabled modules for Apache, I found out that mod_expires was not enabled. So I edited httpd.conf and enabled mod_expires ...

April 17, 2019 · 1 min · Harshvardhan Malpani

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

5 ways to redirect your Web page?

Hi Everyone! In this post we will be learning about redirects. And see how you can redirect your web-page. We will see two ways to redirect web-pages: Through your registrars’ Cpanel. Right into your code. Through cPanel redirect feature You can easily redirect your visitors from one page to another with the help of the Redirects feature. To setup a redirection, access your website’s Control Panel and locate the Redirects menu. ...

January 12, 2019 · 2 min · Harshvardhan Malpani