Magento REST is not Found after http://{magentoHost}/api/ - api

I am trying to access rest API for Guest User through
http://localhost/b_marketing/api/rest/products, but the page redirects to 404 page. I have checked retrive catalog products in ACL attributes RULES, REST - attributes and REST - ROLES, correctly. It also works correctly on my other project by using these all configurations.
There is one thing I need to mention here that my project works only when I use http://localhost/b_marketing/index.php , despite of setting up the htaccess rewrites and setting rewrite from admin panel. My apache rewrites are also set.
When I use http://localhost/b_marketing/api/?wsdl it works and some xml returns.
But I cannot use http://localhost/b_marketing/api/rest/products
The Response Header is always 404.
I also cannot access REST API using http://localhost/b_marketing/index.php/api/rest/products as well.

Make sure you have rewrite rule in .htaccess.
Go to magento root folder, in your case it is b_marketing
Open .htaccess file in any editor
Locate rewrite rule for api
If you don't have .htaccess file in place, you may consider to copy fron original
Magento packagem

If you run nginx:
.htaccess is not supported. Edit the nginx configuration and add the line:
location /api {
rewrite ^/api/rest /api.php?type=rest last;
}
I read that that line sometimes is already there however with the the word break instead of last. Thats wrong, change it to last.

Make sure to use -MultiViews. As the api.php and /api path have the same name (without extension), Apache might resolve api automatically to api.php and cause trouble.

Related

Redirect url for REST service

I am able to reach my website at a certain ip address and I am going to implement a REST service. I have some PHP files that perform actions on a database and I am calling them from the client. I am using linux ubuntu as server and so far I can do this:
http://xxx.xxx.xxx.xxx/api/create/?id=someId&val=someValue
http://xxx.xxx.xxx.xxx/api/delete/?id=someId
I can do the above because inside /var/www/html I have a folder called api that contains another folder called create. The create cointains the file index.php so that I can omit it and execute the URL you can see above.
This works fine but I don't think this is the proper way to do it. I am new with this so I don't know what to do. After some researches I have found that my goal probably be achieved using an .htaccess file use url rewriting but I am not sure.
How can I do this? Do I have to place all the php files in a single folder and then use an htaccess file? (^)
(^) To be more precise: instead of having this
http://xxx.xxx.xxx.xxx/api/create/index.php?id=someId&val=someValue
http://xxx.xxx.xxx.xxx/api/delete/index.php?id=someId
//and so on with other actions...
Do I have to create a folder like
http://xxx.xxx.xxx.xxx/files/
containing all my php files (create.php, delete.php, view.php...) and the use an htaccess to redirect?
I see that websites offer their api using www.domain.com/api/something/?data=Value or www.domain.com/api/something/dataAbout/. Are they doing what I have said about the .htaccess? I hope I have well explained my problem.
htaccess:
RewriteEngine On
RewriteRule ^api/([\w-]+)/?$ files/$1.php [L,NC]
This is inside /var/www/html and I have api inside /home/username/api .
Thanks Emma
Do it like this:
Create php files in a folder files/ subdirectory as create.php, delete.php, view.php etc (by renaming each individual index.php file, you mentioned).
Move away api directory somewhere outside site root.
Once that is done use following .htaccess file in /var/www/html/:
RewriteEngine On
RewriteRule ^api/([\w-]+)/?$ files/$1.php [L,NC]
Then use new URLs as:
http://xxx.xxx.xxx.xxx/api/create?id=someId&val=someValue
http://xxx.xxx.xxx.xxx/api/delete?id=someId
In first, this is not the right way to create a RESTFUL API. My suggestion is to you read a best practices article.
You shouldn't create a CREATE and DELETE folder. You should use HTTP actions.
To create a new record you should use POST. In example, POST /user and in the body you pass the user's information.
In another example, you could use the same route by using different HTTP methods: DELETE /user/1 to delete a user and PATCH /user/1 to edit some already existent user's information.
Hope it's help you.

remove http query parameter from url htaccess

I want to shorten my URI to just my site address that is
http://www.abcdef.org/index.php?pg=23
http://www.abcdef.org/histop.php?pg=1
http://www.abcdef.org/other.php?pg=29
to
www.abcdef.org
How can I rewrite this using my `.htaccess file? I read a lot of articles but could not find any solution.
Use Redirect directive
Redirect /foo.html /bar.html
Apache Documentation
But understand when the user types in whatever URL it will map to your index file in your case. But you can't just hide every URL to the domain name...it doesn't work that way.

Set Base URL using .htaccess

I'm setting up a clients area so my customers can review their site during development. I want to set it up so the URL is http://clients.mydomain.com/clientname/
Is there a way in the .htaccess file to set that as the base URL? I'm using the leading / format for my URLs in the page (ie /about/ or /css/), which will is fine locally & when I deploy to production, but doesn't work in the scenario outlined above.
The proper way would be to use relative links in your HTML, it's unreliable to try to track the referer and rewrite every subsequent request to shove the /clientname/ back in as a prefix.
If you make a subdomain for each customer, and develop sites there, you don't have to change the base URL. This will prevent other htaccess rules to break also when deploying to the live server...
So use:
http://clientname.mydomain.com

Redirecting from example.com to www.example.com

My site uses AJAX, and it seems like I have to include the full path when I use it to access a function. This is fine, as I can code it in. The problem is, I have hardcoded http://www.example.com... but if a user has gone to http://example.com (without the www) this gives an access problem and the AJAX won't execute.
I think the easiest way to resolve this would be to make sure that if a user goes to mysite.com, they are redirected to www.example.com.
I can find solutions online, but they all involve the htaccess file, which my server doesn't support - I have to use rewrite.script instead.
How can I do this using rewrite.script, or is there an alternative way to approach this?
Thanks for the suggestions - I was directed to this: http://seo-website-designer.com/Zeus-Server-301-Redirect-Generator which created the rewrite.script file I needed.
In .htaccess found in your root document:
Redirect http://example.com/ http://www.example.com/
If there is no support for .htaccess on your server, you may have to include meta tag redirect on the head of your page. or using javascript to check the URL source then redirect it.

I want all page requests to point to a single page

The wrinkle is that the pages being requested are aspx pages and they are no longer present. I want any request coming to the root domain (and any subdomain like www) to redirect to a single page in the root directory (namely index.html) I went into the IIS admin tool, selected the domain and tried to direct to a url (http://mydomain.com/index.html) but that caused index.html to be appended multiple times and resulted in an error.
What is the best way to do this, so that any http request ot hsi domain goes to the index.html page?
Thanks in advance.
Warren
You can achieve this using the ASP.Net App_Offline feature; if you place a file in the root of your website called App_Offline.htm, the contents of that file will be returned in response to all incoming requests.
Or find your default 404.html file and put some redirection code into it