Curtis
Curtis

Reputation: 2704

RewriteRule base and specific path

I've basically developed a custom framework for myself that runs all from the index.php using the following .htaccess line

RewriteRule .* index.php [QSA,L]

I have now developed an REST API that I need to run via the same server/root, I've tried adding the following URL to the .htaccess only to be prompted with a custom 404 I've got intergrated into my custom framework, so basically it's ignoring this line and just trying to use the RewriteRule for my custom framework

RewriteRule /api/v1/(.*)$ myAPI.php?request=$1 [QSA,NC,L]

How can I get it so I my API url won't be passed as a query to my other RewriteRule

My .htaccess looks like the following

Options +FollowSymlinks
RewriteEngine on
RewriteOptions MaxRedirects=10

AddType "text/html; charset=UTF-8" html 
AddType "text/plain; charset=UTF-8" txt

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # if file not exists
    RewriteCond %{REQUEST_FILENAME} !-f

    # if dir not exists
    RewriteCond %{REQUEST_FILENAME} !-d

    # avoid 404s of missing assets in our script
    RewriteCond %{REQUEST_URI} !^.*\.(jpe?g|png|gif|css|js)$ [NC]

    # rest api url
    RewriteRule ^api/v1/(.*)$ /myAPI.php?request=$1 [QSA,NC,L]

    # core framework url rewriting
    RewriteRule .* index.php [QSA,L]
</IfModule>

Upvotes: 1

Views: 1141

Answers (1)

anubhava
anubhava

Reputation: 785266

Remove leading slash from your rule:

RewriteRule ^api/v1/(.*)$ /myAPI.php?request=$1 [QSA,NC,L]

.htaccess is per directory directive and Apache strips the current directory path from RewriteRule URI pattern.

Upvotes: 1

Related Questions