New rewrite rules in subdirectory with htaccess

a 夏天 提交于 2019-12-11 06:27:39

问题


I'm struggling with configuring the rewrite rules in the .htaccess files. I'd like to run a Slim PHP App inside my Wordpress folder, so I can reuse the SSL certificate for my API. The Slim App is running inside the /api folder, so it can be accessed by calling 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.

What I did so far:
I excluded the api directory in the .htaccess file inside the Wordpress root 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:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]

回答1:


Just added after a lot of try and error RewriteBase /api to the .htaccess file in the api directory to get it working properly.

The final .htaccess in /api now looks like this:

RewriteEngine On
RewriteBase   /api
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]


来源:https://stackoverflow.com/questions/44732197/new-rewrite-rules-in-subdirectory-with-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!