英文:
Apache WordPress subfolder .htaccess: DirectoryIndex not allowed here
问题
I have a working WordPress site that also serves an old flat-file folder. I have set up a clone environment with Ubuntu 22.04 and XAMPP at home and while the WordPress part is fine trying to access the subfolder causes an error.
[Sun Feb 26 17:36:06.779271 2023] [core:alert] [pid 81557] [client 127.0.0.1:37060] /srv/www/site/classic/.htaccess: DirectoryIndex not allowed here
The folder has the same .htaccess
file that works on the public site:
DirectoryIndex index.html
If I delete .htaccess
I get this error:
[Sun Feb 26 17:42:03.345577 2023] [autoindex:error] [pid 93553] [client 127.0.0.1:48984] AH01276: Cannot serve directory /srv/www/site/classic/: No matching DirectoryIndex (index.php) found, and server-generated directory index forbidden by Options directive
However, after deleting .htaccess
, while you cannot just go to http://site.local/classic/
, it will work with explicit pages like http://site.local/classic/index.html
.
I definitely don't understand these errors since one seems to contradict the other.
Since I don't have control over my public host's httpd-vhosts.conf
, I'm assuming the fault lies there, but whatever the fix is, I'd like to replicate the .htaccess
file in a subfolder setting DirectoryIndex
rather than just a single fix for this one subfolder.
Relevant portion of httpd-vhosts.conf
:
<VirtualHost *:80>
DocumentRoot "/srv/www/site/"
ServerName site.local
<Directory /srv/www/site>
Options FollowSymLinks
AllowOverride Limit Options FileInfo
DirectoryIndex index.php
Require all granted
</Directory>
<Directory /srv/www/site/wp-content>
Options FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
Site root .htaccess
(WordPress default):
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Definitely in learning mode here, so all advice is welcome.
英文:
I have a working WordPress site that also serves an old flat-file folder. I have set up a clone environment with Ubuntu 22.04 and XAMPP at home and while the WordPress part is fine trying to access the subfolder causes an error.
[Sun Feb 26 17:36:06.779271 2023] [core:alert] [pid 81557] [client 127.0.0.1:37060] /srv/www/site/classic/.htaccess: DirectoryIndex not allowed here
The folder has the same .htaccess
file that works on the public site:
DirectoryIndex index.html
If I delete .htaccess
I get this error:
[Sun Feb 26 17:42:03.345577 2023] [autoindex:error] [pid 93553] [client 127.0.0.1:48984] AH01276: Cannot serve directory /srv/www/site/classic/: No matching DirectoryIndex (index.php) found, and server-generated directory index forbidden by Options directive
However after deleting .htaccess
while you cannot just go to http://site.local/classic/
it will work with explicit pages like http://site.local/classic/index.html
.
I definitely don't understand these errors since one seems to contradict the other.
Since I don't have control over my public host's httpd-vhosts.conf
I'm assuming the fault lies there but whatever the fix is I'd like to replicate the .htaccess
file in a subfolder setting DirectoryIndex
rather than just a single fix for this one subfolder.
Relevant portion of httpd-vhosts.conf
:
<VirtualHost *:80>
DocumentRoot "/srv/www/site/"
ServerName site.local
<Directory /srv/www/site>
Options FollowSymLinks
AllowOverride Limit Options FileInfo
DirectoryIndex index.php
Require all granted
</Directory>
<Directory /srv/www/site/wp-content>
Options FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
Site root .htaccess
(WordPress default):
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Definitely in learning mode here so all advice is welcome.
答案1
得分: 1
<Directory /srv/www/site> Options FollowSymLinks AllowOverride Limit Options FileInfo DirectoryIndex index.php
为了能够在.htaccess
中设置DirectoryIndex
(特别是在.htaccess
上下文中覆盖DirectoryIndex
),您需要在AllowOverride
指令中使用Indexes
指令类型。例如:
AllowOverride Limit Options FileInfo Indexes
或者,更常见的做法是使用All
关键字(还包括AuthConfig
- 以允许使用授权指令)。即 AllowOverride All
。
参考链接:
请注意,WordPress配置依赖于设置DirectoryIndex index.php
(用于在请求主页时)。您已在服务器配置中设置了这个。您可以在单个指令中同时设置两者,例如:
DirectoryIndex index.php index.html
(在这种情况下,index.php
优先级更高。)
如果未在任何地方设置DirectoryIndex
,那么默认值是仅 index.html
。
英文:
> <Directory /srv/www/site>
> Options FollowSymLinks
> AllowOverride Limit Options FileInfo
> DirectoryIndex index.php
To be able to set DirectoryIndex
in .htaccess
(specifically, to be able to override the DirectoryIndex
in a .htaccess
context) you need the Indexes
directive-type in the AllowOverride
directive. For example:
AllowOverride Limit Options FileInfo Indexes
Or, what you see more commonly, is the use of the All
keyword (which also includes AuthConfig
- to allow the use of the authorization directives). ie. AllowOverride All
.
Reference:
Note that the WordPress config is dependent on DirectoryIndex index.php
being set (for when the homepage is requested). Which you have set in the server config. You can set both in a single directive, for example:
DirectoryIndex index.php index.html
(index.php
takes priority in this case.)
If the DirectoryIndex
is not set anywhere then the default is index.html
only.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论