问题描述
更新:改变了这一问题的标题,以反映我想要的东西。
UPDATE: Changed the title of this question to reflect what i want
我希望把所有文件中的所有目录作为参数,除了/公/目录下的所有文件和所有子目录,使用的.htaccess。
I wish to treat all files in all directories as parameters, except all files inside the /public/ directory and all its subdirectories, using .htaccess.
我已经尝试了很多东西,但没有工作。我现在的.htaccess文件看起来是这样的:
I have tried many things, but none work. My current .htaccess file looks like this:
DirectorySlash Off
RewriteEngine On
RewriteBase /
# remove access to .htaccess
RewriteCond %{THE_REQUEST} /\.htaccess [NC]
RewriteRule ^ - [F]
# remove access to launcher.php
RewriteCond %{THE_REQUEST} /launcher\.php [NC]
RewriteRule ^ - [F]
# enforce HTTPS
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# treat existing directories as parameters
RewriteCond %{DOCUMENT_ROOT}/$1 -d
RewriteRule ^(.*?[^/])$ %{REQUEST_URI}/ [L]
# handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*?)/?$ launcher.php?url=$1 [QSA,L]
此文件执行以下的事情已经:
This file does following things already:
- 黄柏所有目录,现有的或没有,作为参数
- Dissallows访问的.htaccess和launcher.php
- 强制使用HTTPS
- 重定向所有请求launcher.php
请做笔记,我希望把所有的文件作为参数,不仅dissallow访问。例外情况是/公/文件夹内的所有文件和所有子目录。
Please do note that I wish to TREAT all files as parameters, NOT only dissallow access. Exceptions to this are ALL files inside of the /public/ folder and ALL its subdirectories.
推荐答案
您可以使用此的.htaccess:
You can use this .htaccess:
DirectorySlash Off
RewriteEngine On
# remove access to launcher.php and .htaccess
RewriteCond %{THE_REQUEST} /\.htaccess [NC]
RewriteRule ^ - [F]
# enforce HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# treat existing directories as parameters
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?[^/])$ %{REQUEST_URI}/ [L]
# handle Front Controller for public/
RewriteRule ^(public)/?$ launcher.php?url=$1 [QSA,L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(public/.*?)/?$ launcher.php?url=$1 [QSA,L,NC]
# handle remaining URLs as parameter
RewriteCond %{QUERY_STRING} !(?:^|&)url= [NC]
RewriteRule ^((?!public/).*?)/?$ launcher.php?url=$1 [QSA,L]
这篇关于对待所有文件,除少数例外参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!