我正在尝试使重定向工作,但遇到了麻烦。HTTP 到 HTTPS 重定向确实有效,但尝试创建 RESTful API 却不行。任何想法都将不胜感激。谢谢。
<VirtualHost *:80 *:443>
<Directory /var/www/example.com/public_html>
#Options +FollowSymLinks
Options -Indexes +FollowSymLinks
AllowOverride None
Require all granted
</Directory>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www/example.com/public_html
ErrorLog /var/www/example.com/error.log
CustomLog /var/www/example.com/requests.log combined
RewriteEngine On #only turn on once
#force https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
<Directory "/var/www/example.com/public_html">
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)$ /api/index.php?rquest=$1 [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ /api/index.php [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^(.*)$ /api/index.php [QSA,NC,L]
</IfModule>
</Directory>
</VirtualHost>
编辑:我重写了第二个目录部分,使其如下所示:
<Directory "/var/www/example.com/public_html">
<IfModule mod_rewrite.c>
RewriteEngine On
#force https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)$ /api/index.php?rquest=$1 [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ /api/index.php [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^(.*)$ /api/index.php [QSA,NC,L]
</IfModule>
</Directory>