Disable PHP in Directory (Including All Sub-Directories) With .Htaccess

Disable PHP in directory (including all sub-directories) with .htaccess

Try to disable the engine option in your .htaccess file:

php_flag engine off

Disable a file execution inside a folder .htaccess rule

All you have to do is place that .htaccess file within that specific cache folder.

.htaccess files provide a way to make configuration changes on a per-directory basis.

Apache HTTP Server Tutorial: .htaccess files

Placing that rule in your .htaccess file in the root of your website will enable those rules on your entire site.


If you want this rule to be enabled from outside that cache folder, you might want to try this rule in your main .htaccess file -

RewriteEngine On
RewriteRule ^cache/.*\.(htaccess|htpasswd|ini|...)$ /access_denied.php

The rule tests to see if the requested file's

  • URL starts with cache/
  • contains any of the file extensions listed (separated with a pipe character)

If those conditions are all met, it passes that call to the access_denied.php script where you could display an appropriate error message.

Remove .php from URL in subdirectory

In your /home/user/public_html/sub/.htaccess file, use this code:

Options -MultiViews
RewriteEngine on

# remove php
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{REQUEST_URI} !/index\.php$
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]

# rewrite with php php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/sub/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

removing index.php from subfolder using htaccess not working

You can use this .htaccess in /subfolder/.htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /sub-folder/

# remove index.php from URLs
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ $1 [L,R=302,NC,NE]

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>

disable .php and .html files from my directory listing?

Add the following line to your .htaccess file

   IndexIgnore *.html *.php 

This tells the Apache web server to list all files except those that end with .php and .html .

If you want to disable all files and directories form listing ,Add this line to your .htaccess

  IndexIgnore *

The wildcard '*' means it will not display any files

htaccess direct all pages and sub directories to index.php

Try this.

#Options +FollowSymLinks
Options -Indexes
RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*) index.php [QSA,NC,L]

.htaccess deny files in subfolders

I think the simpliest rule is:

RedirectMatch 403 ^.*/sub/folder/index\.php$

RedirectMatch is in mod_alias module, that you certainly have. This does not implies mod_rewrite engine. Here we are simply telling apache that any access to sub/folder/index.php will generate a "403 forbidden" answer.

You can put that in a httpd.conf or in the root .htaccess (but really consider removing all .htaccess, it's bad, it's slow, it's sad that you do not have access to the real configuration files).



Related Topics



Leave a reply



Submit