Y
Y
yurygolikov2017-02-12 16:44:35
Apache HTTP Server
yurygolikov, 2017-02-12 16:44:35

Apache - mod_rewrite. Write a simple regex. Why does not it work?

OC ubuntu16.04-x86_64
Apache2.4
You need to write a regular expression on apache - mod_rewrite.
1. If the request starts with /api{whatever else}, then we will convert the request to index.php
2. In all other cases, we return index.html.
My version (below) doesn't work for some reason.

RewriteEngine on  
RewriteRule ^api.*$ index.php [L]  
RewriteRule ^.*$ index.html

Thank you.

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/

T
T_y_l_e_r, 2017-02-12
@T_y_l_e_r

RewriteEngine On
RewriteBase /
RewriteRule ^api.*$ index.php [L]  
RewriteRule ^.*$ index.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question