RewriteRule htaccess if a file exists

前端 未结 1 1817
无人共我
无人共我 2021-01-20 05:48

I want to use htaccess to check if a file called offline.txt exists in the same directory as the htaccess file, if it exists then do:

RewriteRule ^.*$ /websi         


        
相关标签:
1条回答
  • 2021-01-20 06:02

    You can't use a relative location for the -f test. You'll need to include the full path:

    RewriteEngine on
    RewriteCond %{DOCUMENT_ROOT}/folder/offline.txt -f
    RewriteCond %{REQUEST_URI} !/websiteOffline.php
    RewriteCond %{REMOTE_ADDR} !^12\.34\.56\.78$
    RewriteRule  ^(.*)  /websiteOffline.php [L]
    

    where /folder/ is the path that your htaccess file is in.

    Here, if your IP address is 12.34.56.78 and you try accessing the folder, it won't redirect you.

    0 讨论(0)
提交回复
热议问题