1

I want to rewrite this url:

http://cyanogenupdatetracker.com/api/v1/show_devices.php

to http://cyanogenupdatetracker.com/api/v1/devices

I used this .htaccess file

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^devices$ devices/
RewriteRule ^devices/$ /var/www/api/v1/show_devices.php

It always returns a 404 error, even though i know and am 100% sure that the php file exists at the given location. I tried everything (no path before php file, custom vhosts, rewritebase) but none of this is working.

The apache config for this dir is as following:

Alias /api /var/www/api
    <Directory /var/www/api>
        Options FollowSymLinks
        DirectoryIndex index.php
        AllowOverride All
    </Directory>

I am completely done with this. It seems so simple (only a few php files) and why has it to be that hard, just to simplify the urls to make them nicer.

What am I doing wrong?????

user35509
  • 11
  • 1

2 Answers2

1

I think your problem is that within the context of a .htaccess file Pass Through is implied.

Effectively that means that your RewriteRule doesn't map to a file-system location but to an URI path. That is needed, among others, to work well with Alias directives. Also check this comparison.

cyanogenupdatetracker.com/api/v1/devices probably ended being redirected to something like cyanogenupdatetracker.com/api/v1/var/www/api/v1/show_devices.php. Your rule should have looked like:

RewriteRule ^devices/$ show_devices.php

Second, my pet peeve, why are you using an .htaccess file in the first place when you obviously have access to the main apache configuration file? Quoted from from the manual on .htaccess files:

You should avoid using .htaccess files completely if you have access to httpd main server config file. Using .htaccess files slows down your Apache http server. Any directive that you can include in a .htaccess file is better set in the main Apache configuration file(s), as it will have the same effect with better performance.
...
Likewise, mod_rewrite directives work better, in many respects, in the main server configuration.

HBruijn
  • 72,524
  • 21
  • 127
  • 192
0

Fixed myself by changing documentroot from /var/www/html to /var/www as the api folder was outside of /var/www/html.

user35509
  • 11
  • 1