Rewrite Rule Not Redirecting To The Specified File

Viewed 38

Recently I started working with .htaccess file to redirect API call to a specific file. However, even though my .htaccess file is working (tested it with just text on top of the file and I get "Internal Server Error") my rule is not working. Instead, Index.php is always read. The goal is, whenever the url ends with "myOwnAPI/" it takes you to the file "somefile.php". All files(index.php, somefile.php, .htaccess) leave in the same directory.

The .htaccess file contains just one rule.

Please help.

httpd.conf file

<Directory />
    AllowOverride All
    Require all denied
</Directory>

AllowOverride All

.htaccess file

RewriteEngine on

RewriteRule   ^myOwnAPI/?$   somefile.php  [NC,L]
1 Answers

Every url start with a "/" so

RewriteRule   ^myOwnAPI/?$   somefile.php  [NC,L]

won't ever match. Change it to

RewriteRule   ^/myOwnAPI/?   /somefile.php  [NC,L]

Moreover, please read the offical documentation https://httpd.apache.org/docs/2.4/rewrite/flags.html if you need to "pass" the parameters to the new url (flag QSA).

Related