apache 301 redirect can i hide url from message - apache

I have set 301 redirection for certain URL and I don't want this message
is there any way to remove URL from this message or just set custom message.
which is showing in response of curl
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved here.</p>
<hr>
<address>Apache/2.4.29 (Ubuntu) Server at x.x.x.x Port 80</address>
</body></html>

Edit /etc/apache2/conf-available/security.conf and set:
ServerTokens Prod
ServerSignature Off

Related

Difference between GET/POST express Response.redirect

I am trying to redirect a user after authentication from a login service to the resource service. There for, when someone tries to access the main page of my app, I check for the auth token inside a cookie and based on that validation, I serve the html file or redirect to the auth service where I am greeting them with a login/register form.
if(cookie?.auth){
return res.status( 301 ).redirect( `${ protocol }://${ process.env.REDIRECT_AUTH }/login?redirect=${ protocol }://${ hostname }:${ PORT }&session=${ req.sessionID }` );
}
This part works as expected. I get redirected to the endpoint. The question mark appears here. After I enter the credentials, I make a post request to the auth service and if everything goes right, I call the res.redirect(location), the location being the redirect query listed in the link above with some parameters as well.
Here is the snippit:
return res.status( 301 ).redirect( `${ location }?auth=${ token }` as string );
Of course, I am checking if the request query contain the credentials I need. The request actually returns 200, but instead of being redirected to the page, I get the file as a response payload.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
HAASDASD
</body>
</html>
My immediate conclusion was that is about the difference between the GET vs POST method and therefor I get a different result. Is there anyone who stumbled into something similar?

Magento Rest API retuning 404 for products page

I've installed / configured Magento 1.9. CE on my local Ubuntu 14 machine by following the guide at https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-magento-on-ubuntu-14-04. I've setup my Magento base as http://localhost.
I then tried accessing the APIs from Java using Scribe. This is the code I have right now:
public final class MagentoAuth {
/**
* #param args
*/
public static void main(String[] args) {
final String MAGENTO_API_KEY = "abc";
final String MAGENTO_API_SECRET = "xyz";
final String MAGENTO_REST_API_URL = "http://localhost/api/rest";
// three-legged oauth
OAuthService service = new ServiceBuilder()
.provider(MagentoThreeLeggedOAuth.class)
.apiKey(MAGENTO_API_KEY)
.apiSecret(MAGENTO_API_SECRET)
.debug()
.build();
System.out.println("" + service.getVersion());
Scanner in = new Scanner(System.in);
System.out.println("Magento's OAuth Workflow");
System.out.println();
// Obtain the Request Token
System.out.println("Fetching the Request Token...");
Token requestToken = service.getRequestToken();
System.out.println("Got the Request Token!");
System.out.println();
System.out.println("Fetching the Authorization URL...");
String authorizationUrl = service.getAuthorizationUrl(requestToken);
System.out.println("Got the Authorization URL!");
System.out.println("Now go and authorize Main here:");
System.out.println(authorizationUrl);
System.out.println("And paste the authorization code here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();
System.out.println("Trading the Request Token for an Access Token...");
Token accessToken = service.getAccessToken(requestToken, verifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: "
+ accessToken + " )");
System.out.println();
OAuthRequest request = new OAuthRequest(Verb.GET, MAGENTO_REST_API_URL+ "/products?limit=2");
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
System.out.println();
}
}
When I run this program, I'm able to successfully get the token, which I then verify from the Magento Admin panel. But then when I paste the token, I get the following error:
404
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /api/rest/products was not found on this server.</p>
<hr>
<address>Apache/2.4.7 (Ubuntu) Server at localhost Port 80</address>
</body></html>
Now, I saw on many forums that adding a block to their Apache conf file worked. I have the following in my conf file (/etc/apache2/sites-available/magento.conf):
<VirtualHost *:80>
DocumentRoot /var/www/html
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
</VirtualHost>
However, I was not sure if that is the place to add. So I also added the <Directory> block in my apache.conf file (/etc/apache2/apache.conf) as well and restarted apache2 server. However, this doesn't help me either. I still get the 404 error. What am I doing wrong here?
Not sure if this has anything to do with the problem ,but I added the sample data provided on Magento's website after installing Magento (even though they have specifically mentioned not to do so) because of which all my default data such as admin user etc were deleted from the database. So I had to add the admin user manually myself in the database. Would this have changed something else?
======================== EDIT ===========================
I edited my .htaccess file and added the following:
## you can put here your magento root folder
## path relative to web root
RewriteBase /var/www/html/
Now, when I try to run my code, it fails even before getting the token with this error:
response status code: 403
response body: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /var/www/html/index.php
on this server.</p>
<hr>
<address>Apache/2.4.7 (Ubuntu) Server at localhost Port 80</address>
</body></html>
Thanks.
Make sure to use Options -MultiViews

Apache Reverse Proxy erases <meta http-equiv="Content-type" content="text/html; charset=utf-8" />

this is my first post here.
I've already searched the forum for a related issue, but none of the results seems to solve my issue.
The setup is:
There is a MS Sharepoint 2010 deployed on IIS 7 in an internal customer network. This seems to behave correctly from within the internal network.
To make this service public, I have an apache 2.2 server running on Red Hat EL 6.0 on a DMZ. The apache has a vhost configured as Reverse proxy to allow the conections from outside.
Due to some links problems i found, I had to compile and integrate mod_proxy_html module to parse those Links.
The problem is that I see strange characters when accessing from outside (through the apache). And it is due to the Apache erasing an html meta tag:
From inside the MZ, the html code starts:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html dir="ltr" lang="es-ES">
<head><meta http-equiv="X-UA-Compatible" content="IE=10" /><meta name="GENERATOR" content="Microsoft SharePoint" /><meta http-equiv="Content-type" content="text/html; charset=utf-8" /><meta http-equiv="Expires" content="0" /><meta name="msapplication-TileImage" content="/_layouts/15/images/SharePointMetroAppTile.png" /><meta name="msapplication-TileColor" content="#0072C6" /><title>
However, when accessed from outside, the html code starts:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html dir="ltr" lang="es-ES">
<head><meta http-equiv="X-UA-Compatible" content="IE=10" /><meta name="GENERATOR" content="Microsoft SharePoint" /><meta http-equiv="Expires" content="0" /><meta name="msapplication-TileImage" content="/_layouts/15/images/SharePointMetroAppTile.png" /><meta name="msapplication-TileColor" content="#0072C6" /><title>
Tag missing: meta http-equiv="Content-type" content="text/html; charset=utf-8".
I have already tried adding to my httpd.conf:
AddDefaultCharset utf-8
ProxyHTMLCharsetOut utf-8
ProxyHTMLMeta On
The virtualhost is configured as follows (130.177.97.99 is the IP belonging to the backend):
<VirtualHost bpocenter-hp:5445>
ServerName www.bpocenter-hp.com
SSLProtocol -all +TLSv1
SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
SSLEngine on
SSLProxyEngine on
SSLCertificateChainFile /etc/httpd/cert_bpo-hp/intermediate.crt
SSLCertificateKeyFile /etc/httpd/cert_bpo-hp/server.key
SSLCertificateFile /etc/httpd/cert_bpo-hp/server.crt
ProxyHTMLEnable On
SetOutputFilter proxy-html
ProxyHTMLLogVerbose On
ProxyHTMLExtended on
ProxyHTMLMeta On
TransferLog "|/usr/serveis/app/apache/bin/rotatelogs /serveis/logs/bpocenter-hp/access_log 86400"
ErrorLog "|/usr/serveis/app/apache/bin/rotatelogs /serveis/logs/bpocenter-hp/error_log 86400"
ProxyRequests Off
ProxyPass / http://130.177.97.99:8065/ ttl=900 timeout=900 Keepalive=On
ProxyPassReverse / http://130.177.97.99:8065/
RequestHeader unset Accept-Encoding
ProxyHTMLLinks a href
ProxyHTMLLinks area href
ProxyHTMLLinks link href
ProxyHTMLLinks img src longdesc usemap
ProxyHTMLLinks object classid codebase data usemap
ProxyHTMLLinks q cite
ProxyHTMLLinks blockquote cite
ProxyHTMLLinks ins cite
ProxyHTMLLinks del cite
ProxyHTMLLinks form action
ProxyHTMLLinks input src usemap
ProxyHTMLLinks head profile
ProxyHTMLLinks base href
ProxyHTMLLinks script src for
ProxyHTMLLinks iframe src
ProxyHTMLEvents onclick ondblclick onmousedown onmouseup \
onmouseover onmousemove onmouseout onkeypress \
onkeydown onkeyup onfocus onblur onload \
onunload onsubmit onreset onselect onchange
SetOutputFilter proxy-html
ProxyHTMLURLMap http://130.177.97.99:8065 https://www.bpocenter-hp.com:5445
Any help would be appreciated.
Thanks.
Juan
I fixed this by using:
xml2EncDefault utf-8

Error (JSON 404): <!DOCTYPE HTML PUBLIC "-//IETF/

When I run "vmc info", I get an error : Error (JSON 404):
cloud#rest:~/cloudfoundry/.deployments/rest/log$ vmc info -t
>>>
REQUEST: get http://api.mwt.needforspeed.info/info
RESPONSE_HEADERS:
content_length : 239
date : Thu, 11 Oct 2012 07:32:17 GMT
content_type : text/html; charset=iso-8859-1
content_encoding : gzip
server : Apache/2.2.22 (Ubuntu)
vary : Accept-Encoding
RESPONSE: [404]
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /info was not found on this server.</p>
<hr>
<address>Apache/2.2.22 (Ubuntu) Server at api.mwt.needforspeed.info Port 80</address>
</body></html>
<<<
Error (JSON 404): <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /info was not found on this server.</p>
<hr>
<address>Apache/2.2.22 (Ubuntu) Server at api.mwt.needforspeed.info Port 80</address>
</body></html>
It looks like you have apache webserver running on port 80.
If you install cloudfoundry to a plain vanilla Ubuntu, it will install nginx as a webserver.
So first stop your apache, normally with:
sudo /etc/init.d/apache2 stop
and than check that your nginx (router in cloudfoundry's term) is running:
source ~/.cloudfoundry_deployment_local
~/cloudfoundry/vcap/dev_setup/bin/vcap_dev -n rest status router
please note that you need the extra -n rest parameter as it seems that you didn't use the default development name: dev_box

wcf service doesn't allow POST

I'm quite new to webervices in general and am getting stuck in (I think) configuring IIS and the webservice itself.
I created a wcf webservice in MVS 2010 and hosted it on IIS7.5 on windows 7.
I use soapUI 4.5.0 to post a message generated from the same wsdl description I created the webservice contract with. Issue is that I get 405 due to the fact that http POST not seems to be supported by the webservice or webserver.
Even though I had the idea the error I get would be sufficient to solve my problem, my lack of knowledge about IIS and webservices makes I can't find the right solution.
Below as much information as I could think of. Hope it is of any help and someone can guide me in the right direction.
Configurations made in IIS:
Authorization rule: allow, all users
Directory browsing: enabled
Handler mappings: features permissions: read, script and execute
Handler mappings: added *.wsdl -> ProtocolSupportModule -> GET, HEAD, OPTIONS, TRACE, POST
Application pools: added entry with identity NetworkService using
.net fw 4.0
This is the message sent:
RAW:
POST http: x.x.x.x:21378/ HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/soap+xml;charset=UTF-8;action="/BootNotification"
XML:
<soap:Envelope xmlns:soap="org/2003/05/soap-envelope" xmlns:ns="urn://Ocpp/Cs/2012/02/">
<soap:Header/>
<soap:Body>
<ns:bootNotificationResponse>
<ns:status>Accepted</ns:status>
<ns:currentTime>${now}</ns:currentTime>
<ns:heartbeatInterval>900</ns:heartbeatInterval>
</ns:bootNotificationResponse>
</soap:Body>
</soap:Envelope>
This is the result returned:
I truncated it to limit the size of this post.
RAW:
HTTP/1.1 405 Method Not Allowed
Cache-Control: private
Allow: GET, HEAD, OPTIONS, TRACE
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Thu, 07 Jun 2012 07:58:09 GMT
Content-Length: 5611
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns=".org/1999/xhtml">
<head>
<title>IIS 7.5 Detailed Error - 405.0 - Method Not Allowed</title>
<style type="text/css">
...
...
...
<div class="content-container">
<fieldset><legend>Most likely causes:</legend>
<ul> <li>The request sent to the Web server used an HTTP verb that is not allowed by the module configured to handle the request.</li> <li>A request was sent to the server that contained an invalid HTTP verb.</li> <li>The request is for static content and contains an HTTP verb other than GET or HEAD.</li> <li>A request was sent to a virtual directory using the HTTP verb POST and the default document is a static file that does not support HTTP verbs other than GET or HEAD.</li> </ul>
</fieldset>
</div>
<div class="content-container">
<fieldset><legend>Things you can try:</legend>
<ul> <li>Verify the list of verbs enabled for the module handler this request was sent to, and ensure that this verb should be allowed for the Web site.</li> <li>Check the IIS log file to see which verb is not allowed for the request.</li> <li>Create a tracing rule to track failed requests for this HTTP status code. For more information about creating a tracing rule for failed requests, click here. </li> </ul>
</fieldset>
</div>
<div class="content-container">
<fieldset><legend>Links and More Information</legend>
This error means that the request sent to the Web server contained an HTTP verb that is not allowed by the configured module handler for the request.
<p>View more information »</p>
</fieldset>
</div>
</div>
</body>
</html>
XML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" ".org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns=".org/1999/xhtml">
<head>
<title>IIS 7.5 Detailed Error - 405.0 - Method Not Allowed</title>
<style type="text/css">
...
</head>
<body>
<div id="header"><h1>Server Error in Application "SHENZIWEBSERVICEDEPLOYED"</h1></div>
<div id="server_version"><p>Internet Information Services 7.5</p></div>
<div id="content">
<div class="content-container">
<fieldset><legend>Error Summary</legend>
<h2>HTTP Error 405.0 - Method Not Allowed</h2>
<h3>The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used.</h3>
</fieldset>
</div>
<div class="content-container">
...
</div>
<div class="content-container">
<fieldset><legend>Most likely causes:</legend>
<ul> <li>The request sent to the Web server used an HTTP verb that is not allowed by the module configured to handle the request.</li> <li>A request was sent to the server that contained an invalid HTTP verb.</li> <li>The request is for static content and contains an HTTP verb other than GET or HEAD.</li> <li>A request was sent to a virtual directory using the HTTP verb POST and the default document is a static file that does not support HTTP verbs other than GET or HEAD.</li> </ul>
</fieldset>
</div>
<div class="content-container">
<fieldset><legend>Things you can try:</legend>
<ul> <li>Verify the list of verbs enabled for the module handler this request was sent to, and ensure that this verb should be allowed for the Web site.</li> <li>Check the IIS log file to see which verb is not allowed for the request.</li> <li>Create a tracing rule to track failed requests for this HTTP status code. For more information about creating a tracing rule for failed requests, click here. </li> </ul>
</fieldset>
</div>
<div class="content-container">
<fieldset><legend>Links and More Information</legend>
This error means that the request sent to the Web server contained an HTTP verb that is not allowed by the configured module handler for the request.
<p>View more information »</p>
</fieldset>
</div>
</div>
</body>
</html>
This is part of the generated servicecontract (wsdl /language:CS /serverInterface
// CODEGEN: The optional WSDL extension element 'PolicyReference' from namespace 'http://schemas.xmlsoap.org/ws/2004/09/policy' was not handled.
[ServiceContract(Name = "CentralSystemServiceSoap", Namespace = "urn://Ocpp/Cs/2010/08/")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
[System.Web.Services.WebServiceBindingAttribute(Name="CentralSystemServiceSoap", Namespace="urn://Ocpp/Cs/2010/08/")]
public interface ICentralSystemServiceSoap {
/// <remarks/>
[OperationContract]
[System.Web.Services.Protocols.SoapHeaderAttribute("chargeBoxIdentity")]
[System.Web.Services.WebMethodAttribute()]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("/BootNotification", RequestElementName = "bootNotificationRequest", RequestNamespace = "urn://Ocpp/Cs/2010/08/", ResponseElementName = "bootNotificationResponse", ResponseNamespace = "urn://Ocpp/Cs/2010/08/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
[return: System.Xml.Serialization.XmlElementAttribute("status")]
RegistrationStatus BootNotification(string chargePointVendor, string chargePointModel, string chargePointSerialNumber, string chargeBoxSerialNumber, string firmwareVersion, string iccid, string imsi, string meterType, string meterSerialNumber, out System.DateTime currentTime, [System.Xml.Serialization.XmlIgnoreAttribute()] out bool currentTimeSpecified, out int heartbeatInterval, [System.Xml.Serialization.XmlIgnoreAttribute()] out bool heartbeatIntervalSpecified);
I didn't understand how your service is built and what you have done there, but from my experience, this is a simple way to create a wcf RESTful service that supports POST requests:
http://www.codeproject.com/Articles/201901/CREATE-RESTful-WCF-Service-API-Using-POST-Step-By
Update according to the comments:
try using that:
[OperationContract]
[WebInvoke(Method = "POST")]
[System.Web.Services.Protocols.SoapHeaderAttribute("chargeBoxIdentity")]
[System.Web.Services.WebMethodAttribute()]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("/BootNotification", RequestElementName = "bootNotificationRequest", RequestNamespace = "urn://Ocpp/Cs/2010/08/", ResponseElementName = "bootNotificationResponse", ResponseNamespace = "urn://Ocpp/Cs/2010/08/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
[return: System.Xml.Serialization.XmlElementAttribute("status")]
RegistrationStatus BootNotification(string chargePointVendor, string chargePointModel, string chargePointSerialNumber, string chargeBoxSerialNumber, string firmwareVersion, string iccid, string imsi, string meterType, string meterSerialNumber, out System.DateTime currentTime, [System.Xml.Serialization.XmlIgnoreAttribute()] out bool currentTimeSpecified, out int heartbeatInterval, [System.Xml.Serialization.XmlIgnoreAttribute()] out bool heartbeatIntervalSpecified);
UPDATE
try doing that:
On IIS 7.5 -> YourWebsite -> Handler Mappings
Choose "Add module mapping" option on the right side of the panel
In "Request path" field enter *.wsdl
In "Module" field enter "ProtocolSupportModule"
Click on "Request restrictions" and go to Verbs tab
Enter POST verb
Save changes