user10012
user10012

Reputation: 715

htaccess File Rewriting API Routes

I am trying to redirect all incoming traffic to my site to index.php and put the remainder of the url in a path variable. I also have a index.html in my root directory and if the user accesses it directly I want them rerouted to the index.php script.

  RewriteEngine On
  RewriteBase /
  RewriteCond $1 !^index\.html  
  RewriteCond $1 !^index\.php
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^index\.html?$ / [NC,R,L]
  RewriteRule ^(.*)$ index.php?path=$1 [L,QSA]

The rerouting seems to be working ok, but all my /api/index.php?route=xx&mode=xx seem to be getting rerouted too. Is there a way to exclude the api directory from the rewrite condition?

Upvotes: 0

Views: 735

Answers (1)

RavinderSingh13
RavinderSingh13

Reputation: 133528

Could you please try following. This is checking if REQUEST_URI is not starting from /app/index.php then reroute everything to index.php along with passing parameters to it, couldn't test it as of now, will test it few mins or so.

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/api/index\.php/?$ [NC]
RewriteRule ^(.*)$ index.php?path=$1 [QSA,L]


RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} ^/api/index(\.html)/?$ [NC]
RewriteRule ^(.*)$ index.php [NC,L]

Upvotes: 1

Related Questions