How to implement Canonical Tag in Pimcore CMS? - canonical-link

I have to implement canonical tags on a customer website which works with Pimcore CMS. Does somebody has experience with that or can give me some hints?

A way could be to set a Document Property and render it in your view.
see: https://pimcore.com/docs/4.6.x/Development_Documentation/Tools_and_Features/Properties.html
For PHP Templating Engine you could add this line and set it properly in your Backend.
<link rel="canonical" href="<?= $this->document->getProperty('canonicalHref');?>" />

If you want to set this tag globally, or with some simple url regex matching, you can do it straight from the admin panel using Marketing > Tag & Snippet Management.

To allow a user to customize URL you can create the predefined property 'canonicalHref',
then put in layout twig file:
<head>
....
{% set canonicalUrl = document.getProperty('canonicalHref')|default(app.request.getUri??'') %}
<link rel="canonical" href="{{ canonicalUrl }}"/>
</head>
You will still need:
to customize HTTP headers in PDF files generated for the print version
and to add 301 redirects from HTTP to HTTPS version.

Related

Open URL in a new tab/window with CGI [duplicate]

For a banner management system i use a
header("Location: http://www.awebsite.com");
to redirect to the proper website. Is it possible to force this header script to open in a new window?
<a href='yourbannerscript.php' target='_blank'>...</a>
No. If you want a new window, you have to deliver the redirect as HTML/Javascript.
This works for me
echo "<script>window.open('yoursite.com');</script>";
It would be nasty, and might not be want you want, but including an IFRAME tag pointing to a php file with the header redirect could be a solution. Doesn't create a new window, but creates a window-within-a-window.
<iframe src="/myredirectscript.php"></iframe>
You should redirect to a page with a redirect metà tag like the one on the most voted answer at Open HTML meta redirect in new window
So the page you redirect your headers to will contain a metà tag with:
<meta http-equiv="refresh" />
<meta content="0; URL=javascript:window.open('http://uri.of
.your.pagewhereyouwabtoredirect/path','_parent');"/>
It's Not possible.. Instead of that you can set open new tab in form attribute target="_blank"
<form target="_blank" method="post" action="contact-function.php">

Shopify add new index.html page with url https://myshopifyshop/index.html

I am working with external tracking service. They sent my index.html file, which looks like this:
<html>
<head>
<!-- tag -->
<script type="text/javascript" src="//path.js"></script>
</head>
<body>
</body>
</html>
They want us to upload this file to shopify and sent them the url to it. The url should look like this https://myshopifyshop/index.html. I couldn't find any article how to upload or create new blank html page with .html extension. Is this somehow possible?
You can't create an html page that will follow the root url of your site.
But you can upload a html page as an asset and link that asset as a page.
Example url will be:
https://cdn.shopify.com/s/files/1/*****/*****/t/4/assets/index.html
But I don't think that this will do you any good, since tracking services requires you to track the current site and not a dummy file that no one will ever open.
It's highly possible that the only important part is the script and everything else is not needed.
So you actually may need to add the script in your layout/theme.liquid file and ignore the rest.
Please contact the the tracking service and let them know that you are not using a static HTML site, but a Shopify one and what steps should you follow.

Resolving js and css urls affected by app.Map in ASP.NET 5

I am implementing multi-tenancy based on the first folder segment of the request url.
As such I'm configuring each tenant separately by branching with IApplicationBuilder like this:
PathString path = new PathString("/somefolder");
app.Map(path,
branchApp =>
{
// code goes here to configure the branch
}
as a result of this if my view has a link with url /Home/About for example, it automatically is adjusted to be relative to the folder I branched on when I visit /somefolder, ie the links change to /somefolder/Home/About, somefolder/Home/Contact etc
This was kind of unexpected to me but actually helpful.
But also if my view has
<link rel="stylesheet" href="~/css/site.css" />
<script src="~/js/lib/jquery/dist/jquery.js"></script>
those now resolve to /somefolder/css/site.css and /somefolder/js/lib/jquery/dist/jquery.js
which is not what I want.
Is there some way I can change this behavior for js and css but keep it for navigation links?
No, you can't. At least, not easily: when using app.Map, it automatically sets HttpContext.Request.PathBase with the path parameter you specified, which causes the exact behavior you're seeing (it's basically a "virtual directory" equivalent).
The best option is to stop using virtual path links (~/) and replace them by standard root-relative links (/), that are not processed by Razor and MVC.
<link rel="stylesheet" href="/css/site.css" />
<script src="/js/lib/jquery/dist/jquery.js"></script>

MVC 4 razor actionlink address route adds pound char in between

the reason of this question is because I am having troubles with a route address in MVC 4 application, what is happening here is that I have an action link in this way in a view:
<li>#Html.ActionLink("Description", "Action", "Controller")</li>
And when I run the app in the HTML in the web browser appear the link generated correct
<li>description</li>
but when I click on the link in the web address bar the destination route appears as follows:
http://localhost:port/#/Controller
Is inserting a "#" char in between, is doing this for all of the links in my different views, it do the same when I deploy the App in a web server too no only in my local and this makes that the destination page don't appear correct, I don't know the reason of this, I have been searching but without success, hope you can help me, thanks in advance.
I found the reason for that behavior, it was because I have the script load for jquery mobile on the head section in the _Layout_cshtml file like this
<head>
<meta charset="utf-8" />
<title>#ViewBag.Title</title>
<meta name="viewport" content="width=device-width" />
#Scripts.Render("~/bundles/jquery")
#Styles.Render("~/Content/mobilecss", "~/Content/css")
#Scripts.Render("~/bundles/modernizr")
#Scripts.Render("~/bundles/jquerymobile")
</head>
What I do was change the location of jquerymobile script to the end of the _Layout.cshtml
#Scripts.Render("~/bundles/jquerymobile")
#RenderSection("scripts", required: false)
</body>
With this change the web route was created correctly, I hope this helps to somebody.

SSL and W3 XHTML Validator

This may be a dumb newbie question, so appologies for that.
My website is using a SSL certificate. I also include the W3 validator link in each of my webpages as follows:
<img src="valid-xhtml1.png" alt="Valid XHTML 1.0 Strict" height="31" width="88" />
(Note: copied over the w3 validator image so SSL wouldn't complain about unsecure resources).
When I do this, and click on the image to validate the page, I get this message from the validator:
The error mentions requesting the validator unsecurely. So I tried changing the href of the <a> tag to use https for the validator, but then the page simply doesn't load (I guess because the validator doesn't use SSL).
Does anyone know a way around this? I am guessing there is not a way to use the code as is, but maybe there is a way to update uri=referer to be uri=https://mysite.com/...? Is there a way to dynamically grab the URL of the current page?
Also, just for further reference, does SSL simply prevent the referer request header from being accessed?
Oh, and I know I can just go to my website using http instead of https, and the validator works. But I'd rather get it configured to work with https too.
As for the "validate icon" question:
This would usually lead to displaying a messages about "unsecure items" (=mixed http+https content)... the validate icon is not officially supported in such constellation... a partial workaround is described here.
IF you want to grab the uri dynamically I suspect you will have to use JavaScript for that and then create/add the <a> in the DOM...
As for the SSL/Referer question:
The standard says that a client (=browser) should send referer only if the destination is secure - so yes, in mixed cases the referer won't get sent to the non-secure URL.
Ok, so it's not looking like there is a way to do this with just HTML. So instead, I decided to use JavaScript to handle the issue.
I removed the <a> tag from around the W3 logo and added an onclick JavaScript function validatePage(). So here is basically a template for an XHTML Strict page that still allows you to include the validation icon.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Title of document</title>
<script type="text/javascript">
function validatePage() {
var validatorUrl = "http://validator.w3.org/check?uri=http" + (document.URL).substring(5);
window.open(validatorUrl);
}
</script>
</head>
<body>
<h1>Test Template Page</h1>
<p><img src="valid-xhtml1.png" alt="Valid XHTML 1.0 Strict" height="31" width="88" onclick="validatePage()" /></p>
</body>
</html>
Notice how the validatorUrl variable trims off the "https" from the URL and instead uses "http". So I just circumvented using the HTTP referer header.
Hope this helps someone else.