Htacess redirect index file when trying to access directory

Attempt to deny access to all files except index.pl. First, I deny everything, after which I allow access to index.pl. The following code is working correctly.

Order Allow,Deny
Deny from all
<Files "index.pl">
    Order Deny,Allow
    Allow from all
</Files>

But after adding the .htaccess file with this content, the following problem appeared: When I try to access mysite.com/( without index.pl), the server says that it is forbidden.

I tried to add DirectoryIndex index.pl, the code became like this:

Order Allow,Deny
Deny from all
<Files "index.pl">
    Order Deny,Allow
    Allow from all
</Files>

DirectoryIndex index.pl

This did not help me.

What should I write in the file to restrict all files except index.pl and the site will work correctly, without adding /index.plfor the link? Maybe there is another way to do what I want? Thank!

ps: Sorry for my not very good english.

+3
2

mod_rewrite . DOCUMENT_ROOT/.htaccess:

RewriteEngine On

RewriteCond %{REQUEST_URI} !\.(jpe?g|gif|bmp|png|tiff|css|js)$ [NC]
RewriteRule ^(?!(index|search)\.pl).+$ - [F,NC]
+1

<Files> <FilesMatch> index.pl :

<FilesMatch "^(index.pl)?$">
    Order Deny,Allow
    Allow from all
</FilesMatch>
+2

All Articles