我在ubuntu上有一个apache2服务器。我使用apache配置文件来实现多种功能,例如隐藏文件扩展名,将http转发到https等。我的配置文件具有副作用,即对domain.net/api(或任何其他子目录)的请求返回404,而不是该目录的索引文件。
我的apache虚拟主机具有以下配置文件(其中@用于匿名)。没有正在使用的htaccess文件。
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin @@@@
ServerName @@@@@@.net
ServerAlias www.@@@@@@.net
DirectoryIndex index.php
DocumentRoot /var/www/@@@@@@.net/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/var/www/@@@@@@.net/html">
AllowOverride All
</Directory>
<Directory "var/www/@@@@@@.net/html/api">
DirectoryIndex index.php
</Directory>
# Custom error pages
ErrorDocument 400 /error
ErrorDocument 401 /error
ErrorDocument 403 /error
ErrorDocument 404 /error
ErrorDocument 500 /error
RewriteEngine on
# Remove www
RewriteCond %{HTTP_HOST} ^www\.@@@@@@\.net$
RewriteRule ^(.*)$ https://@@@@@.net$1 [R=301,L]
# Remove trailing slash
RewriteCond %{THE_REQUEST} ^(?!GET./.H.*$)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ $1 [L,R=301]
# Rewrite /foo/bar to /foo/bar.php
RewriteCond %{REQUEST_FILENAME} !^/$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]
# Return 404 if the original request is /foo/bar.php
RewriteCond %{THE_REQUEST} "^[^ ]* .*?\.php[? ].*$"
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* - [L,R=404]
# SSL stuff
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/@@@@@.net/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/@@@@@.net/privkey.pem
</VirtualHost>
</IfModule>