[英]New rewrite rules in subdirectory with htaccess
I'm struggling with configuring the rewrite rules in the .htaccess files. 我正在努力在.htaccess文件中配置重写规则。 I'd like to run a Slim PHP App inside my Wordpress folder, so I can reuse the SSL certificate for my API. 我想在我的Wordpress文件夹中运行一个Slim PHP应用程序,以便可以为我的API重用SSL证书。 The Slim App is running inside the /api folder, so it can be accessed by calling https://www.example.com/api
. Slim应用程序在/ api文件夹中运行,因此可以通过调用https://www.example.com/api
进行访问。
This works well, but if I open an API endpoint like example.com/api/timesheet
the page is redirected to the 404 error Wordpress page. 效果很好,但是如果我打开API端点(例如example.com/api/timesheet
该页面将重定向到404错误的 Wordpress页面。
What I did so far: 到目前为止,我做了什么:
I excluded the api directory
in the .htaccess
file inside the Wordpress root directory: 我在WordPress根目录下的.htaccess
文件中排除了api directory
目录:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(api|api/.*)$
RewriteCond %{HTTPS} !on
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
And added these new Slim default rules in the .htaccess
file inside the api directory
: 并在api directory
内的.htaccess
文件中添加了这些新的Slim默认规则:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
Just added after a lot of try and error RewriteBase /api
to the .htaccess
file in the api directory to get it working properly. 经过多次尝试和错误RewriteBase /api
才将其添加到api目录中的.htaccess
文件中,以使其正常工作。
The final .htaccess in /api
now looks like this: 现在, /api
的最终.htaccess如下所示:
RewriteEngine On
RewriteBase /api
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.