Y
Y
yurygolikov2017-02-12 13:12:58
Apache HTTP Server
yurygolikov, 2017-02-12 13:12:58

Apache - mod_rewrite. The regex doesn't work correctly. What is the problem? How to write correctly?

Hello. Didn't work much with apache - mod_rewrite. But now I had to.
The regex doesn't work correctly. For any requests, including /api/blabla/blabla - it returns index.html, but it should be index.php.
Checked here - everything works correctly. But I don't. It seems that the flag [L] does not work. Mb they need to be included somehow?

RewriteEngine on
RewriteRule ^api($|/+.*$) index.php [L]
RewriteRule ^.*$ index.html

(a simplified version of the place that doesn't work)
What I need:
1. If the request starts with /api{whatever else}, then we convert the request to index.php
2. In all other cases, return index.html.
Please help. Thank you very much!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
yurygolikov, 2017-02-12
@yurygolikov

The solution turned out to be this.

RewriteEngine On
RewriteCond %{ENV:REDIRECT_FINISH} !^$
RewriteRule ^ - [L]
RewriteRule ^api($|/+.*$) index.php [E=FINISH:1,L]
RewriteRule ^.*$ index.html [E=FINISH:1,L]

The point was that mod_rewrite could enter an infinite loop.
More about this:
https://habrahabr.ru/post/75885/
https://habrahabr.ru/company/sprinthost/blog/129560/

V
VisualIdeas, 2017-02-12
@VisualIdeas

RewriteRule ^api(.+)$ /index.php [L]
Slash before index

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question