I'm using restler to write a REST api, and since I wan't to do some basic authentication I need to redirect every request wich doesn't come from https, to https.
Does anybody know a way of doing this using the .htaccess file provided by restler or is it better to do this redirection using php headers?
Thanks in advance!
Approach that works for me is to do it from index.php (gateway) place the code below in your index.php before any other code
if($_SERVER['HTTPS']!="on")
{
$redirect= "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
header("Location:$redirect");
exit;
}
Related
We needed to implement SSL for our Zabbix monitoring frontend and it's caused havok on some of our backend scripting (which would be more trouble than it's worth to fix).
I'm currently working under the theory that I should be able to use some redirection magic in order to:
Access our normal Zabbix Frontend via HTTPS
Access our API via HTTP (this is the key hangup right now).
Initially - redirection was easy enough:
<VirtualHost *:80>
ServerName <servername>
RedirectMatch /zabbix/(.*) https://<servername>/zabbix/$1
</VirtualHost>
But this causes all sorts of issues with our API calls needing to still be done via HTTP (which is being done via a scripts calling API values to drive interface selections in other tools). I actually end up getting a 412 response.
So I thought I could maybe do something like this:
RedirectMatch /zabbix/(!api_jsonrpc.php)(.*) https://<servername>/zabbix/$2
While this will still let my API succeed over HTTP, it doesn't redirect my zabbix frontend to HTTPS.
This has been driving me nuts! Any help would be appreciated.
Sample URLS:
https://<servername>/zabbix/zabbix.php?action=dashboard.view
https://<servername>/zabbix/index.php
http://<servername>/zabbix/api_jsonrpc.php
Ultimately - anything that isn't "api_jsonrpc.php" needs redirected to HTTPS, and anything with that value needs to go over HTTP.
We are using Apache 2.2 and upgrading is not currently an option.
Ultimately, the issue I was having was coming down to the fact that you can't really redirect POSTs.
To resolve this, I ended up winning my argument that he library file update (forcing all traffic over HTTPS) and mass push was the only working solution and we're now golden.
You cannot negate strings just by prefixing them with an exclamation mark, lookarounds would have to be used.
I don't think API requests pass any GET parameters - try the following:
RedirectMatch /zabbix/(.*)(?<!api_jsonrpc\.php)$ https://<servername>/zabbix/$1
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.
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'm new to Apache mod_rewrite but I was able to get it to work for simple URL translation for static pages accessed using the GET method.
I'm having trouble to get the URL translation to work for web services though. Basically all I want is to redirect the request from Apache to tomcat that runs under 8093 . I tried:
RewriteRule myproject/myservices/myService/(.*) http://www.localhost:8093/myproject/myservices/myService/$1
But I get a "The document has moved here" response. Any ideas would be appreciated. Thanks.
I think the problem is that your request is only rewritten, but not proxied. You could try to append [P] at the end or look into mod_proxy: http://httpd.apache.org/docs/2.0/mod/mod_proxy.html
i am getting canonical issue in my web site. the error is as follows:
The page with URL "http://dynamicsexchange.com/images/CRMcommunity_supersources_withspaces.jpg" can also be accessed by using URL "http://www.dynamicsexchange.com/images/CRMcommunity_supersources_withspaces.jpg".
all errors i got are related to non-www and www so, please tell me how to set www.mysite.com for my site.
Thanks and Regards
M Prasad Reddy
If it's asp 2 and above you can implement it in 2 ways:
1) ASP.NET: Redirecting with ASP.NET and IIS
you can implement 301 redirects using ISAPI Rewriting modules, products like UrlRewriter.NET which is discussed in Chapter 3, "Provocative SE-Friendly URLs," of the book, Professional Search Engine Optimization with ASP.NET: A Developer's Guide to SEO, or from within your ASP.NET code by setting the appropriate header data.
When using ISAPI_Rewrite, redirecting is implemented similarly to URL rewriting, except that you specify a redirection status code as a parameter.
Example :
The following rule does a 301 redirect to Catalog.aspx when the initial request is for Catalog.html:
301 Redirect Catalog.html to
Catalog.aspx RewriteRule
^/Catalog.html$
http://seoasp/Catalog.aspx [RP]
2) In Code
If you want to implement the redirect yourself, you need to manipulate the response headers using the Response object provided by your current HttpContext object. Here's how to 301 redirect Catalog.html to Catalog.aspx yourself:
if (context.Request.Path == "/Catalog.html")
{
context.Response.Status = "301 Moved Permanently";
context.Response.AddHeader("Location", "http://www.example.com/Catalog.aspx");
}
Explanation: The first URL should be a relative path to the old URL and the second one should be an absolute path to the new URL.