AMP form amp_source_origin error cors header - forms

I am getting error in AMP Form
<form class="innler-left" method="post" action-xhr="//mydoma.com/ xxxx/xxx/xxx/send.php" target="_top">
On submit getting below error in console.
Response must contain the AMP-Access-Control-Allow-Source-Origin header
Form submission failed: Error:
Response must contain the AMP-Access-Control-Allow-Source-Origin header​​​ _reported_
Once user submit the form it goes it php file in where I put the following header
header('HTTP/1.1 200 OK');
header("access-control-allow-credentials:true");
header("AMP-Same-Origin: true");
header("Access-Control-Allow-Origin:".$_SERVER['HTTP_ORIGIN']);
header("amp-access-control-allow-source-origin: https://".$_SERVER['HTTP_HOST']);
header("Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin");
header("access-control-allow-headers:Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token");
header("access-control-allow-methods:POST, GET, OPTIONS");
header("Content-Type: application/json");
I got it working offline on local machine but once i upload files, it not working :(
tried https://github.com/ampproject/amphtml/blob/master/spec/amp-cors-requests.md
POST __amp_source_origin is not matching!

I was also facing the same issue to fix this, make sure your URL start with https. And try to replace the following line in your code :
header("Access-Control-Allow-Origin:".$_SERVER['HTTP_ORIGIN']);
with
header("Access-Control-Allow-Origin: ". str_replace('.', '-','https://www.example.com') .".cdn.ampproject.org");
Note : Replace https://www.example.com with your AMP website URL
Hope it helps.

Related

TYPO3 how to render a Page on 404 with correct status code

we are using:
TYPO3 8.7.27
RealUrl 2.5.0
following scenario - a user enters a link that does not exist within our site - so we expect the behaviour that a 404 page gets rendered - we managed to achive that but we do not have the correct status code because we used a simply redirect within the install tool:
[FE][pageNotFound_handling] = "REDIRECT:/404"
[FE][pageNotFound_handling_statheader] = "HTTP/1.0 404 Not Found"
we also use our 404 page for cHash comparison errors but thats just a sidenote.
so what happens is the user requests the data from the wrong url, we send the correct 404 followed by a redirect to a certain page.
how can we directly render a page in the first place, the url should stay the same and we just render our whole TYPO3 page (no static file) with the 404 text-information.
You should use this instead:
[FE][pageNotFound_handling] = "/404"
This will instruct TYPO3 to download the page at the given "URL" and output its content together with the expected 404 status code. Notice that it might be necessary to use an absolute URL here.
From the DefaultConfigurationDescription.php:
pageNotFound_handling
... String: Static HTML file to show (reads content and outputs with correct headers), e.g. "notfound.html" or "http://www.example.org/errors/notfound.html"
You can drop the pageNotFound_handling_statheader option since it defaults to 404.

VueJS 400 Bad Request on image source binding

I have this VueJS site and im having issues loading some images. I receive a json response which i can loop over the properties no problem but when Im looping over the image src i get a 400 bad request for each image.
Failed to load resource: the server responded with a status of 400 (Bad Request)
http: //vue.dev/images/staff/%07Thompson_Jen.jpg
<div class="col-sm-4" v-for="employee in staff">
<img :src="'/images/staff/'+employee.imageName">
</div>
if i navigate to the image through the dev tools it will try to load the above url but if try manually in the url without the %07, it works or if i hardcode the path it also works. Not sure why it is tacking on the %07.Does VueJS encode properties for attributes?
There must be something in the JSON response that includes that BEL (%07) character. VueJS is just adding whatever string it sees on the end there. That character doesn't print so that would explain why you're not seeing it anywhere.

Server Error in '/' Application after submitting a form

New to coding here... Just got my validation form working, now after submitting the form, I am getting a Server Error in '/' Application after submitting form. This type of page is not displayed.
<form action="ContactUsResults.cshtml" method="POST">
When I change my page type to .htm
<form action="ContactUsResults.htm" method="POST">
Then I get the 405 error message 'Method Not Found'
Ideally, I am just trying to get to a confirmation page after they submit the form.
Thanks!
The web server that is running as part of your WebMatrix environment is not configured to allow the POST method, hence the 405 "Method Not Found" error. You will need to enable the POST method in settings or a configuration file in order for your form action to work.

Should I make Joomla return a 404 error when page is not found for SEO purposes?

I'm using Joomla 2.5 and I have edited the error.php to include the following PHP code:
if (($this->error->getCode()) == '404') {
header('Location: /404');
exit;
}
This is if someone links to domain.com/SomethingBogus they don't get the standard Joomla page for 404 error. So I created an Article called 404 and put it in a hidden menu and now when that happens it displays the information such as "Sorry you are having a problem...report this here...etc".
But I did a 'wget' on this and it returns a 200 status which means the page is OK. I've been told that I should still return a 404 error, otherwise SEO wise you get punished by Google.com. OK, I understand that but how do I do both? If so, how do I do that because I don't believe you can use a header of 404 not found error and also redirect it to an information page using:
<?php
if ($this->error->getcode() == '404') {
header("HTTP/1.0 404 Not Found");
} ?>
I have seen web pages which says something is not found which may be returning a 404 error and then waits 5 seconds and then does the redirect. If that is the answer how do I do that in Joomla? Thanks!

Facebook can't scrape my site correctly - PHP Site

I am running this website www.miswag.net which is highly dependent on Facbeook. When I share my site on Facebook, I get a "403 Forbidden", here's Facebook's debugger output when I try to scrape my site: https://developers.facebook.com/tools/debug/og/object?q=http%3A%2F%2Fwww.miswag.net
Please help figure this out.. Thanks
Facebook's scraper doesn't need to read the full page, so they only request part of it by sending a Range header. However, your server seems to be responding incorrectly to that request and returning a 403 error code. You need to check your server and make sure it handles the range header correctly.
To see this in action, try this CURL command:
curl -H "Range: bytes=0-524287" http://www.miswag.net
This is the response I got:
<!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 /
on this server.</p>
<p>Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html>
Compounding on #Waleed'sanswer, if you want to test right away, use Online CURL
fill in www.wiswag.net
ADD OPTION options, choosing --header (-H)
next to it "Range: bytes=0-524287"
CURL button