I am trying to configure an htaccess file for the first time. I've searched around and can't figure out what I'm doing wrong. I'm attempting to do the following:
1 - I would like http://localhost/phpinfo to load phpinfo.php (This works) located in /var/www/phpinfo/php
2 - I would like http://localhost/products to load api/product/read.php (located in /var/www/api/product/read.php) but it returns a 404 - The requested URL /products/ was not found on this server
I'm obviously configuring the .htaccess (located in /var/www/.htaccess) file wrong but have got myself completely confused!
.htaccess file
<IfModule mod_rewrite>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/phpinfo/$ phpinfo.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/products/$ api/product/read.php [NC,L]
</IfModule>
Apache.config for AllowOverride
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
#<Directory /srv/>
# Options Indexes FollowSymLinks
# AllowOverride None
# Require all granted
#</Directory>
Any ideas or pointing in the right direction would be greatly appreciated :-)
Update taking on board comments (thank you), still no joy :-(
So, now I have modified the .htaccess file as follows. I've moved the phpfile out of the root directory as I thought that might have been giving me a false positive, which it turned out was the case.
<IfModule mod_rewrite>
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/?phpinfo/?$
RewriteRule ^(.*)$ /api/phpinfo.php [NC,L]
RewriteCond %{REQUEST_URI} ^/?products/?$
RewriteRule ^(.*)$ /api/product/read.php [NC,L]
</IfModule>
Now, neither rewrites are working, I get a 404 for both http://localhost/phpinfo and http://localhost/products.
File structure is now:
/var/www/api/phpinfo.php
/var/www/api/product/read.php (no change from the above but included for reference)