Apache 2 + PHP - .htaccess 权限问题
Apache 2 + PHP - Issue with .htaccess permissions
我已经创建了一个 apache2 环境来执行 PHP 网络应用程序。
几乎一切正常。
这是我的应用结构:
/var/www/html/
- app/: PHP classes directory
- views/: PHP templates directory
- storage/: database and log stuffs directory
- static/: public directory for js, css and images
- index.php: Main script
- .htaccess
下面是 .htaccess 文件
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule \.(static/)$ - [L]
RewriteCond %{REQUEST_URI}:: ^(/.+)(.+)::$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
</IfModule>
重定向到 index.php 工作正常。我只想允许访问目录 static/ 并拒绝任何其他请求并将其重定向到 index.php.
这可能吗?
您可以在您的 .htaccess 中使用此代码:
RewriteEngine On
RewriteRule ^index\.php$ - [L,NC]
RewriteCond %{THE_REQUEST} !\s/+static/ [NC]
RewriteRule ^ index.php [L,NC]
# remaining rules go here
我已经创建了一个 apache2 环境来执行 PHP 网络应用程序。
几乎一切正常。
这是我的应用结构:
/var/www/html/
- app/: PHP classes directory
- views/: PHP templates directory
- storage/: database and log stuffs directory
- static/: public directory for js, css and images
- index.php: Main script
- .htaccess
下面是 .htaccess 文件
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule \.(static/)$ - [L]
RewriteCond %{REQUEST_URI}:: ^(/.+)(.+)::$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
</IfModule>
重定向到 index.php 工作正常。我只想允许访问目录 static/ 并拒绝任何其他请求并将其重定向到 index.php.
这可能吗?
您可以在您的 .htaccess 中使用此代码:
RewriteEngine On
RewriteRule ^index\.php$ - [L,NC]
RewriteCond %{THE_REQUEST} !\s/+static/ [NC]
RewriteRule ^ index.php [L,NC]
# remaining rules go here