Restler always showing NOT FOUND on server, but not on local machine - php

When I go to
http://localhost/api/auth/login
I get what I expect.. some data that lets me log in.
However, when I go to
http://myurl.com/api/auth/login
I just get
{
"error": {
"code": 404,
"message": "Not Found"
}
}
Currently we have 2 people working on this project, and both of us, when we run it from our local machines, have no issues. We're to the point where we are putting the app on to a hosted server so that we can start testing it outside of our own machines.
The code is identical, and I know this because we use a git repository in which the server is also pulling from.
My machine is a mac, my buddy's is a windows machine, and our host is a linux box. This shouldn't really matter, since all of them should work with mod_rewrite, a requirement for Restler 3.
The only other details I can think of is that the server is hosted by HostMonster, running PHP 5.4.7
Any help would be GREATLY appreciated. Do you need more information?
=== Edit:
This is my .htaccess file. Also, the server runs CGI/FastCGI not mod_php
Options -MultiViews
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ index.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
<IfModule mod_php5.c>
php_flag display_errors Off
</IfModule>
I just googled 'fastcgi mod_rewrite' and none of those links helped :P

When ever you come across such issue first try without url rewriting
instead of
http://myurl.com/api/auth/login
try
http://myurl.com/api/index.php/auth/login
If it works you will know that the issue is with url rewriting
Since you are using CGI/FastCGI make sure you have set
cgi.fix_pathinfo=0
in your php.ini it will make sure that path info is passed to Restler properly so that restler can find the route
If it does not work with index.php in the url, you can try generating and verifying routes.php as explained below
routes.php
Restler looks at all api methods and its doc comments to generate routes accordingly every time we run it on debug mode. When we run it on production mode it captures the information in routes.php and uses it instead of generating routes every time thus improving efficiency.
You can check for the generated routes by initializing restler in production mode and refresh on every call
$r = new Restler(true, true);
and then check the generated routes.php
If your routes.php contains no routes it will appear as follows
<?php $o = array();
// ** THIS IS AN AUTO GENERATED FILE. DO NOT EDIT MANUALLY **
return $o;
If this is your case, it means some how autoloader is failing to load the api class, you can confirm it by manually including the API classes
If it starts to work, please file a bug using github issues stating that the autoloader is failing for your server configuration and give us more detils so that we can reproduce it and fix it.
If it still does not work, please file a bug using github issues mentioning your server configuration and give us any detail that could help so that we can reproduce it and fix it.
Thaks to you, we will also write a trouble shooting guide based on above to help the restler community :)

Related

server error using URI embedded images in a required file if index.php isn't in the url

Struggling. Help!
In index.php:
require "cachedPages/home.html";
If I visit: https://websiteaddress.org/index.php then it works fine.
If I visit: https://websiteaddress.org then I get an internal server error.
I guess it's a .htaccess thing. All I have in there is some cpanel php72 code and:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
DirectoryIndex index.php
It seems there's some difference between how index.php is called if you call it directly as opposed to .htaccess calling it for you?!?
Any ideas?
Thanks in advance.
If you don't have one of the following options in your .htaccess then Apache won't know which file to default back to:
DirectoryIndex index.php
FallBackResource /index.php
Also I'd recommend installing mod_rewrite as well. It's handy for other reasons.
Well, I've managed to sort the problem, but it's a pretty weird situation that no-one else will probably ever experience. Here goes...
If the user lands at:
https://websiteaddress.org rather than https://websiteaddress.org/index.php
and that page (php) requires another page,
which has images that are embedded as URIs rather than linked src files.
Then, the first URI causes a server error.
If I replace the
img src='data:image/jpeg;base64,/998a9g98ahg...etc'
with
img src='path/to/file.jpg'
on the first instance of a jpg then it all works fine.
All the later URIs are fine, it's just the first instance!
It all works now, with this workaround; and the situation is so unique and bizarre that I doubt this thread will be of use to anyone else. In fact it's so edge-case that I can't be bothered investigating it any further myself.

404 error with Slim - tried everything

I'm trying to build an API for the first time by using PHP to access a MySQL server, and going off of AndroidHive's tutorial here but customizing it to be my own simple API instead of the task manager one listed. My problem is, I can't even get to the part where I test anything (I'm using XAMPP for Mac) because I keep getting 404 errors when I attempt to access a method in my index.php file.
Here's my .htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L]
I already changed my XAMPP Apache httpd.conf file to "AllowOverride All" as per the Slim documentation instructions, and tried restarting the server a billion times but to no avail. No matter what I do, if I ever try to test any of the URLs in my index file (for instance at localhost/w_manager/v1/register) it just returns a 404 not found error.
I even updated my .htaccess file to add in "RewriteBase /v1" though that did not seem to make much of a difference - got another 404 object not found error.
I've also looked around on Stackoverflow a ton. I'm about to pull out my hair. Does anyone have any other suggestions? Thanks!
Well, I seem to have fixed it - not exactly sure how, unfortunately, but what I did was go back and copy the sample code into my own and make alterations (after I noticed that the sample code worked.) One major change I made was that in my index.php file, I moved the Slim request definitions at the beginning and moved all other functions to the end, just before $app->run(). Hope this will help someone else!

File not found with .htaccess file on Apache server

I have this .htaccess on my Windows dev machine and everything works fine
RewriteEngine On
RewriteRule ^(.+[^/])/$ http://%{HTTP_HOST}/webserv/$1 [R=301,L]
RewriteRule ^login/([0-9]+)/([0-9]+)$ login.php?par1=$1&par2=$2 [L,NC,QSA]
When I upload it on my Centos server I get the error
404 The requested URL path_to_script/login.php was not found on this server.
I cannot understand why this is. The file is definitely there and I gave permissions 777.
I have checked if the .htaccess is actually used by adding rubbish in it and getting an internal error (500) which means that it is working.
Also when I use .htaccess to make restrictions on IPs that have access to the directory it works. mod_rewrite is loaded as shown in the phpinfo() I have tried.
I am at a loss here.
EDIT
I noticed that it tries to search in the base_path appending it to the root path e.g.
/path_to_script/path_to_script/login.php
And that is why it fails. How do I solve this?
I finally solved it but in a way that I am not sure I like. At least it works. If someone has a better solution I would be glad to see it.
RewriteRule ^login/([0-9]+)/([0-9]+)$ http://host/webserv/login.php?par1=$1&par2=$2
The reason I don't like this solution is because I does not give a pretty url. It just redirects.
I still do not understand why I get the root directory appended to the request if I instead write:
RewriteRule ^login/([0-9]+)/([0-9]+)$ login.php?par1=$1&par2=$2

Mod-rewrite not working on Network Solutions server

I have a website that requires mod-rewrite to function well, but it seems to not be functional on the Network Solutions shared server we're running on. Network Solutions promises it's installed but won't provide any further support without additional payment.
I placed a simple test at the following folder which contains two files. The first, ".htaccess" contains the following text:
RewriteEngine On
RewriteRule ^link([^/]*).html$ rewrite.php?link=$1 [L]
The second is the PHP script which tests it, available here:
http://www.oceanhousefloridakeys.com/testmr/rewrite.php
All I see is that mod-rewrite is installed (no error messages showing) but the rewriteRule is not working. Can anybody see why this script isn't working... is there anything I can do to get it running, or is Network Solutions not telling the whole truth?
It looks like your script resides inside a sub-directory. In that case it's the best solution to set the RewriteBase to the correct path (before any RewriteRule):
RewriteEngine On
RewriteBase /testmr/
RewriteRule ^link([^/]*).html$ rewrite.php?link=$1 [L]

Prefix of my domain is messing things up... How do I resolve this?

I am writing a Facebook app and for it to work properly, I need to set the Site URL inside the Application settings. The problem is that if I set my Site URL to be
domain.com
it works on my system and a bunch of systems that I tested it on. Some of my friends complain that it is not working on their system. When I looked at what the error was, it was sending me back this:
Given URL is not allowed by the Application configuration.
which is telling me that the referrer URI that I am sending it is not what it is expecting in the Application settings. So what I did was I changed the URL to:
www.domain.com
and now my friends are able to use the application and it is failing to load on my end. Does anyone know how to fix this issue? Both cases, I tested it on Windows and Ubuntu with the same browser version yet I am seeing this problem and I don't seem to understand why this is happening.
Ok I am not a fan of this solution myself but consider this a hack... This really should be fixed on Facebook end :(
Step 1: In the Facebook Site-URL field of your application just put www.domain.com
Step 2: Create a .htaccess file in the app directory and put the following text in it:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=permanent,L]
Hope that helps someone with the same behavior.

Categories