0

I have a site being served by an Apache server, with the following structure:

  • On the main directory, I have a front-end app.

  • On a subdirectory named API, I have an API running on Laravel.

When I make calls to the API the URL look like this: domain/api/api/specific-route I would like it to look like this: domain/api/specific-route

This is the relevant part of the virtual host config file:

ServerName my-domain.com
ServerAlias www.my-domain.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/my-domain

<Directory /var/www/my-domain>
        RewriteEngine On
        RewriteBase /

        # Serve files when they are found 
        RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
        RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
        RewriteRule ^ - [L]

        # When file is not found, serve index.html instead
        RewriteRule ^ /index.html
</Directory>
 
<Directory /var/www/my-domain/api>
        RewriteEngine on
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
        Require all granted
</Directory>

ErrorLog /var/www/my-domain/error.log
CustomLog /var/www/my-domain/access.log combined

# Aliases
Alias /api /var/www/my-domain/api/public
Ezequias Lopes
  • 129
  • 1
  • 11
  • is it a laravel project?? Laravel has convenient features to accomplish API and front end . No need to change htaccess file – zohrehda Aug 30 '22 at 02:41
  • Post your Laravel API routes file. Why are you meddling with the htaccess file? – kjoedion Aug 30 '22 at 03:22
  • Laravel API routes are under the /api URI, the Laravel project is under a directory called api, which makes the route to calling the Laravel API methods something like: domain.com/api/api/specific-route. I would like to not have to use API word two times on the URL. I know I can do that with a rewrite rule on the host config file, but I'm not sure how. – Ezequias Lopes Aug 31 '22 at 14:16

0 Answers0