Conditional index directory in .htaccess

Is it possible to make the DirectoryIndex value in the file .htaccessconditional based on IP, so for example, see my IP address DirectoryIndexas index.html, and everyone else sees it DirectoryIndexas index.php?

Is there a solution other than mod_rewrite?

+3
source share
2 answers

As far as I know, there are no conditions for DirectoryIndex. You could mimic this with a mod_rewrite directive like this:

RewriteCond %{REMOTE_ADDR} your_ip
RewriteCond -d
RewriteRule (.*)/$ $1/index.html

If you want to exclude other site visitors from viewing index.html, then also use

RewriteCond %{REMOTE_ADDR} !your_ip
RewriteRule (.*)/index.html$ $1/index.php
+4
source

Using the information provided, I believe that you need the following:

RewriteCond %{REMOTE_ADDR} ^your_ip$
RewriteRule (.*)/$ $1/index.php

RewriteCond %{REMOTE_ADDR} !^your_ip$
RewriteRule index.php$ index.html

, IP- index.php, index.html

, :

DirectoryIndex index.html

RewriteCond %{REMOTE_ADDR} ^your\.ip\.000\.000$
RewriteRule ^index.html$ index.php
+2

Source: https://habr.com/ru/post/1720657/


All Articles