Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
171 views
in Technique[技术] by (71.8m points)

apache - write .htaccess to make all the files n folders present in a folder to be served on my website when in maintenance mode (403 (forbidden mode))?

I have the following file structure in cPanel

web_root_folder_
               |____.neverDelete/_____
               |                     |_____img/logo-30.png
               |                     |_____js/error-page.js
               |                     |_____css/error-page.css
               |
               |____403.shtml
               |
               |____.htaccess

I wanted to write .htaccess with some code that puts the website in 'maintenance mode'. So...I wrote 403.shtml page, which uses external css, javascript and images stored in .neverDelete folder.

I wrote the following code in .htaccess

# The WORKING CODE (Too Long ??)
Deny From All
<FilesMatch 404-layout.min.css>
    Allow From All
</FilesMatch>
<FilesMatch logo-small-transparent-30.png>
    Allow From All
</FilesMatch>
<FilesMatch error-page.js>
    Allow From All
</FilesMatch>

This code successfully worked. It implemented a 403(forbidden) for all files except the 3 files (mentioned in .htaccess file)

but, I want to make all the files n folders present in .neverDelete/ to be served on my website when in maintenance mode.

So i visited http://httpd.apache.org/docs/1.3/mod/core.html#directory to get help. I wrote the code in .htaccess below that actually gave in a 500(server error).

# WRONG CODE
Deny From All
<Directory .neverDelete/ >
    Allow From All
</Directory>

How can I make all the files n folders present in .neverDelete/ to be served on my website when in maintenance mode.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Thanks to @CBroe

In the .htaccess file, we can't use a <Directory> container, since the .htaccess file itself defines the directory.

Since .htaccess defines the directory...we can put a .htaccess file in the .neverDelete/ directory with the following code

Allow from all

This will make the contents of the .neverDelete/ directory always available.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...