I use TYPO3 6.2.
I'm working on a very special page which is not ready for public but I discovered that Google already found it and indexed it. This a a real problem because the page has to be available only for the 2018 summer.
If I disable the page in the back-end then I can still work on it and the page is no longer available for other people, but the URL generates a 404 Not Found.
-> How to generate a 301 redirect to the homepage instead ?
localconf.php or installtool settings:
#have to be 1
$TYPO3_CONF_VARS['SYS']['curlUse'] = 1;
#have to be empty
$TYPO3_CONF_VARS['EXTCONF']['realurl']['_DEFAULT']['init']['postVarSet_failureMode'] = '';
#logical part
$TYPO3_CONF_VARS['FE']['pageNotFound_handling'] = '/404.html';
$TYPO3_CONF_VARS['FE']['pageNotFound_handling_statheader'] = 'HTTP/1.1 301 Moved Permanently';
$TYPO3_CONF_VARS['FE']['pageNotFound_handling'] = 'USER_FUNCTION:fileadmin/scripts/pagenotfound.php:user_pagenotfound->pagenotfound';
content of user function (fileadmin/scripts/pagenotfound.php)
<?php
define('REDIRECTPAGE', '/');
class user_pagenotfound {
function pagenotfound($param, $conf) {
$server_name = $_SERVER;
header("HTTP/1.0 301 Moved Permanently");
print '<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>301 Moved Permanently</title>
<SCRIPT LANGUAGE="JavaScript">
<!--
function doRedirect() {
window.location="http://'.$server_name.REDIRECTPAGE.'";
}
doRedirect();
// -->
</script>
</head>
<body style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;text-align:center;";>
<div style="font-size:20px;text-align:center">The page you have requested cannot be found</div>
<div>If you are not automaticly redirected in 3 seconds please click here: <br />
<br /><a href='.$server_name.'>'.$server_name.'</a></div>
</body>
</html>';
exit;
}
}
?>
Source from here: http://www.typo3forum.net/discussion/34942/301-moved-permanently-statt-404-page-not-found by smartlife
And: http://blog.marit.ag/2009/03/20/korrektes-404-error-handling-mit-typo3/
So I've set image to display:none using a media query.
#media only screen and (max-width:530px) {
img {
display: none;
}
}
I have also tried putting the image/s in a parent div, then setting that display to none. That didn't work either.
<div id="right">
<img src="images/meeting.jpg" />
</div>
But if you view Chrome dev tools, you can see that it still requests it.
Image
How can I disable the image from being requested but only when in mobile view or specific width (using a media query)
When you run the snippet below and check with developer tools, you will see that 100 and 200 are downloaded. But 300 is not.
.hide {
display: none;
}
/* demo with placehold images */
/* this image is downloaded */
<img src="http://placehold.it/100">
/* this image is downloaded */
<img class="hide" src="http://placehold.it/200">
/* this image is NOT downloaded */
<div class="hide">
<img src="http://placehold.it/300">
</div>
You could also move all css to media query:
#media only screen and (min-width:530px) {
#right>img {
display:block;
content: url("https://i.stack.imgur.com/5Sdkx.png");
}
}
#media only screen and (max-width:530px) {
#right>img {
content: '';
}
}
<!doctype html>
<html lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div id="right">
<img src="" />
</div>
</body>
</html>
EDIT
Please, see this link
Good morning,
I have a form on a test AMP page (is AMP validate) and the form works: I receive the email with result (I use a php to handle it).
I don't know (I did some try but I think I still missing an example) the syntax for let the AMP page responce correctly (now I get "Subscription failed!" but I do get the email) or redirect after submission.
Here my example:
AMP page with form (I receive form result after submission but I don't know how to redirect or get "Subscription successful!" message)
Non AMP page with form (I receive form result and it redirect correctly)
action-xhr file destination code:
Code of the php here in txt format (the file that handle the form result)
Any example will be great for me also only about redirect.
Thank you
You can redirect user after successful submission, however it can only be done if you are submitting values to a secure URL (like https://www.example.com).
HTML With AMP-Form
<!doctype html>
<html amp lang="en">
<head>
<meta charset="utf-8">
<script async src="https://cdn.ampproject.org/v0.js"></script>
<title>Hello, AMPs</title>
<link rel="canonical" href="http://example.ampproject.org/article-metadata.html" />
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<script type="application/ld+json">
{
"#context": "http://schema.org",
"#type": "NewsArticle",
"headline": "Open-source framework for publishing content",
"datePublished": "2015-10-07T12:02:41Z",
"image": [
"logo.jpg"
]
}
</script>
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}#-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}#-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}#-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}#-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}#keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<script async custom-element="amp-form" src="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script>
</head>
<body>
<h1>Hello World!</h1>
<form target="_top" action-xhr="https://test.php" method="post" name="test">
<input type="text" name="name" value="ABRA KA DABRA!">
<input type="submit"/>
</form>
</body>
</html>
SUBMISSION REQUEST HANDLER CODE IN PHP
<?php
if(!empty($_POST))
{
$name = $_POST['name'];
/*/ this is the email we get from visitors*/
$domain_url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]";
$redirect_url = 'https://example.com/thank-you';
/*//-->MUST BE 'https://';*/
header("Content-type: application/json");
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Origin: *.ampproject.org");
header("AMP-Access-Control-Allow-Source-Origin: ".$domain_url);
/*/ For Sending Error Use this code /*/
if(!mail("email#example.com" , "Test submission" , "email: $name <br/> name: $name" , "From: $name\n ")){
header("HTTP/1.0 412 Precondition Failed", true, 412);
echo json_encode(array('errmsg'=>'There is some error while sending email!'));
die();
}
else
{
/*/--Assuming all validations are good here--*/
if( empty($redirect_url))
{
header("Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin");
}
else
{
header("AMP-Redirect-To: ".$redirect_url);
header("Access-Control-Expose-Headers: AMP-Redirect-To, AMP-Access-Control-Allow-Source-Origin"); }
echo json_encode(array('successmsg'=>$_POST['name'].'My success message. [It will be displayed shortly(!) if with redirect]'));
die();
}
}?>
This post helped me create an AMP redirect response for C# thank you:
public virtual ActionResult AmpRedirect(string redirectUrl, string __amp_source_origin)
{
if (redirectUrl != string.Empty)
{
HttpContext.Response.AddHeader("AMP-Redirect-To", redirectUrl);
HttpContext.Response.AddHeader("AMP-Access-Control-Allow-Source-Origin", __amp_source_origin);
HttpContext.Response.AddHeader("Access-Control-Expose-Headers", "AMP-Redirect-To, AMP-Access-Control-Allow-Source-Origin");
}
HttpContext.Response.AddHeader("Content-type", "text/json");
return Json(new {Content = ""});
}
Thank you for the guidance here. I'm also unable to get this code to work. I've uploaded the code to my server and tested on-line. Upon clicking submit, the text submitted disappears; there is no success or error message. The email is never received by my inbox.
Here is the exact code that I use, just replacing "mywebsite" with the real name of my site:
HTML
<!doctype html>
<html amp lang="en">
<head>
<meta charset="utf-8">
<script async src="https://cdn.ampproject.org/v0.js"></script>
<title>FORM TEST</title>
<link rel="canonical" href="http://mywebsite.com/index.html" />
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<script type="application/ld+json">
{
"#context": "http://schema.org",
"#type": "NewsArticle",
"headline": "Open-source framework for publishing content",
"datePublished": "2015-10-07T12:02:41Z",
"image": [
"logo.jpg"
]
}
</script>
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}#-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}#-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}#-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}#-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}#keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<script async custom-element="amp-form" src="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script>
</head>
<body>
<h1>FORM TEST!</h1>
<form target="_top" action-xhr="http://mywebsite.com/MAILER2.php" method="post" name="test">
<input type="text" name="name" value="Enter your name here...">
<input type="submit"/>
</form>
</body>
</html>
PHP
<?php
if(!empty($_POST))
{
$name = $_POST['name'];
/*/ this is the email we get from visitors*/
$domain_url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]";
$redirect_url = 'http://mywebsite.com/index.html';
/*//-->MUST BE 'https://';*/
header("Content-type: application/json");
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Origin: *.ampproject.org");
header("AMP-Access-Control-Allow-Source-Origin: ".$domain_url);
/*/ For Sending Error Use this code /*/
if(!mail("admin#mywebsite.com" , "Test submission" , "email: $name <br/> name: $name" , "From: $name\n ")){
header("HTTP/1.0 412 Precondition Failed", true, 412);
echo json_encode(array('errmsg'=>'There is some error while sending email!'));
die();
}
else
{
/*/--Assuming all validations are good here--*/
if( empty($redirect_url))
{
header("Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin");
}
else
{
header("AMP-Redirect-To: ".$redirect_url);
header("Access-Control-Expose-Headers: AMP-Redirect-To, AMP-Access-Control-Allow-Source-Origin"); }
echo json_encode(array('successmsg'=>$_POST['name'].'My success message. [It will be displayed shortly(!) if with redirect]'));
die();
}
}?>
I don't know what's wrong with my embed script, to my logic it should properly embed the video in the frame, but it loads a framed view of www.youtube.com instead of my video video.
There are 2 files in a single directory:
ClassMedia.php:
<?php
class Media {
public function embedYT($code){
echo "<iframe width='560' height='349' src='http://www.youtube.com/embed/".$code." frameborder='0' allowfullscreen></iframe>";
}}
Demo.php:
<?php include "classMedia.php"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Demo</title>
</head>
<body>
<?php
$media = new Media();
$code = "XSGBVzeBUbk";
$media-> embedYT($code);
?>
</body>
</html>
You're missing a single quote right after src='http://www.youtube.com/embed/".$code.", you want this:
echo "<iframe width='560' height='349' src='http://www.youtube.com/embed/".$code."' frameborder='0' allowfullscreen></iframe>";
Note the added single quote.
YouTube ends up seeing a bad URL (http://www.youtube.com/embed/$code frameborder= where $code is the real code) and hands you the homepage instead of what you think you were asking for.
I'm playing around with Sinatra, and I would like to make one of my routes case insensitive. I tried adding the route like this:
get "(?i)/tileflood/?" do
end
But it doesn't match any permutation of /tileflood as expected. I tested the following regex on rubular.com, and it matches just fine. Am I missing something?
\/(?i)tileflood\/?
You want a real regexp for your route:
require 'sinatra'
get %r{^/tileflood/?$}i do
request.url + "\n"
end
Proof:
smagic:~ phrogz$ curl http://localhost:4567/tileflood
http://localhost:4567/tileflood
smagic:~ phrogz$ curl http://localhost:4567/tIlEflOOd
http://localhost:4567/tIlEflOOd
smagic:~ phrogz$ curl http://localhost:4567/TILEFLOOD/
http://localhost:4567/TILEFLOOD/
smagic:~ phrogz$ curl http://localhost:4567/TILEFLOOD/z
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body { text-align:center;font-family:helvetica,arial;font-size:22px;
color:#888;margin:20px}
#c {margin:0 auto;width:500px;text-align:left}
</style>
</head>
<body>
<h2>Sinatra doesn't know this ditty.</h2>
<img src='/__sinatra__/404.png'>
<div id="c">
Try this:
<pre>get '/TILEFLOOD/z' do
"Hello World"
end</pre>
</div>
</body>
</html>
smagic:~ phrogz$ curl http://localhost:4567/tileflaad
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body { text-align:center;font-family:helvetica,arial;font-size:22px;
color:#888;margin:20px}
#c {margin:0 auto;width:500px;text-align:left}
</style>
</head>
<body>
<h2>Sinatra doesn't know this ditty.</h2>
<img src='/__sinatra__/404.png'>
<div id="c">
Try this:
<pre>get '/tileflaad' do
"Hello World"
end</pre>
</div>
</body>
</html>