假设你的htaccess在
/api/
文件夹,应该是这样的
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /api/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?request=$1 [L,QSA]
</IfModule>
注意:不要使用
http://
否则将是外部重定向。此外,使用
QSA
从初始url附加查询字符串的标志。
从您的示例中:
https://example.com/api/search/article?mh=7
将被改写为
/api/index.php?request=search/article&mh=7
编辑:如果你想要每个
http
要重定向到的API的url
https
相等的
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /api/
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/api/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?request=$1 [L,QSA]
</IfModule>