G
G
grepfreecd grepfreecd2016-08-04 12:57:20
Yii
grepfreecd grepfreecd, 2016-08-04 12:57:20

How to redirect all requests for example from site.loc/ to site.loc/api using .htaccess?

Hello. I can't figure out how to redirect all requests so that the application considers its base url to be site.loc/api .
On the main site there is wordpress, and in the subdirectory (actually connected as Apache config api.conf ) there is a yii2 application.
What is the BEST way to do this? I would be grateful for examples for the .htaccess file
DocumentRoot looks in the web folder of the yii2 application. basic template.
Here is the content of api.conf:

<Directory "/var/www/api/web">
    Options FollowSymLinks
    DirectoryIndex index.php
    Require all granted
</Directory>

Alias /disp /var/www/api/web

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew, 2016-08-04
@impwx

Try with mod_rewrite . To do this, it must be connected as a module (as a rule, this is done by default).

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} !api/.*
RewriteRule ^/(.+) /api/$1 [NC,L]

I can’t check if it doesn’t work right away - you can try to remove-add slashes.

G
grepfreecd grepfreecd, 2016-08-04
@nurik_6

And if the .htaccess file is outside the root directory specified in the apache config, will it act on the subdirectory ?
In my case, it turns out that my root is /var/www/api/web
But the /var/www/api directory also contains a .htaccess file. Will the .htaccess file from the parent directory affect the /web directory in this case?
Provided that in the main apache config DocumentRoot is /var/www, but for api.conf it was set, your DocumentRoot as /var/www/api/web

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question