Wordpress add redirect to 404 - javascript

could here someone know please?
Wordpress redirected to similar parent page if this exists, I need to add redirect to 404
For example I’ve created page
Website.com/parent1/child2
If I put
Website.com/parent2/child2
It’s redirected me to
Website.com/parent1/child2
So I need to 404 page, any ideas?
I’m also try use plugins

you can try below code to redirect specific page url to 404 page.
add_action( 'template_redirect', 'redirect_404_to_homepage' );
function redirect_404_to_homepage(){
if(is_404()):
wp_safe_redirect( home_url('/') );
exit;
endif;
}

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://example.com/404-page");
exit();
?>
In this example, the code uses the header() function to send a 301 "Moved Permanently" HTTP status code and a new location header to redirect the user to the http://example.com/404-page URL.
Note that this code should be placed at the top of your 404.php template, before any other HTML or PHP code. You should replace http://example.com/404-page with the URL of the custom 404 page you want to redirect to.

Related

Is a 301 redirect the same as changing window.location?

I am a web developer who also works in SEO.
I want to 301 redirect one page to another page.
Is this 301 redirect for Google beyond what I write below for you?
In JavaScript:
<script>
window.location.replace("https://example.com");
</script>
In PHP:
<?php
header("Location: https://example.com");
?>
Are these two 301 redirects, or do we have to write .htaccess in the cat file, for example?
You can not do this with JavaScript.
But you can use PHP as follows
<?php
header("Location: https://example.com", TRUE, 301);
exit;
?>
Syntax header
header(header, replace, http_response_code)
Changing the URL with window.location in JavaScript is not a 301 redirect. JavaScript runs after the page has been generated on the server. Your JavaScript to change the URL would likely run on a page that has a 200 OK status.
That being said, Google treats JavaScript redirects very similarly to 301 permanent redirects. In most cases, Google will choose not to index the redirecting URL and pass the link juice from it to the target of the redirect.
On the other hand, clients that don't execute JavaScript won't see your JS powered redirect. That includes other search engines like Bing, Baidu, and Yandex, as well as broken link checkers and other SEO analysis tools.
Furthermore, even to Google, 301 redirects are a much stronger signal than a JavaScript redirect. Google is most likely to honor a redirect when it is a 301 Permanent variety compared to JS redirects, 302 Temporary redirects, or meta refreshes.
If you have the ability and opportunity to implement server side 301 Permanent redirects, you should do so instead of JS redirects.

JavaScript | ColdFusion - Facebook pixel

I'm trying to trigger my Facebook pixel.
This is the problem:
I have my own image pixel installed in a client website, when my pixel is triggered in the client website it sends a request to my server which after some inserts in a db I redirect the request to CFML page (HTML for ColdFusion) which has the pixel code from Facebook like below:
<script>
// Facebok Pixel Init Code
fbq('init', 'PIXEL_ID');
fbq('trackCustom', 'myCustomEvent', {});
</script>
<noscript>
<img src="THE_FB_URL/?id=PIXEL_ID&ev=myCustomEvent&noscript=1">
</noscript>
When I directly access the page via a browser it triggers the pixel successfully and I can see it in the Facebook pixel report. But when the request is redirected to the page after the insert to the db the pixel does not trigger.
I think its because the JavaScript and HTML is never added to the DOM so it never gets executed...
Do you know how can I achieve this?
I think if maybe I send an HTTP GET request to the <img> tag URL hopefully the Facebook accepts it..
UPDATE
So this is what happens, the request I send triggers the event, but #Jules is right. I can't find which ad led to a conversion using this method, the problem is that where pushing traffic to our clients website, in which we can't install any JavaScript code.
I tried to check what cookies Facebook stores so when I make the GET request I send those values too, but this happens:
1 - The ad sends the user to a link like this:
l.facebook.com/l.php?u=redirect_url&h=some_token_here
In this page I can check that there is some cookies (I assume these are the values Facebook needs to find which ad led to a conversion)
2 - Then the user is redirected to our clients form page
I tried to check the cookies here too but the cookies don't seem to exist..
I need help people!
So guys,
I made it work this way:
Instead of using CFLOCATION to redirect the request to the CFML page where the Facebook JS snippet is, I directly use CFHTTP to request the Facebook Tracking URL. Like so:
<cfif #source# eq 'facebook'>
<cfhttpparam type="url" name="id" value="PIXEL_ID">
<cfhttpparam type="url" name="ev" value="myCustomEvent">
<cfhttpparam type="url" name="noscript" value="1">
</cfif>
It worked! :)
Based on your comments, the below might work. You'll exploit the noscript image tag.
I think what you want to return with CFML is a CFLocation to the proper FB pixel URL - rather than cfhttp loading it. This way the client still loads the FB pixel, and you still track it's loading in between.
The browser loads
<img src="//your-server.net/trackPixel.cfm?some_vars=some_vals">
That CFML does...
<!--- DO YOUR STORAGE AND OTHER LOGIC --->
<cfquery>...</cfquery>
<!--- THEN REDIRECT --->
<cflocation url="the_official_fb_image_url.gif" addToken="no">
So when the user's browser loads your cfm as an image, reply is to load a different image.
You should not write HTML/Javascript code.
The first conversion pixel is called via an img tag so you cannot respond with HTML/Javascript.
All you have to do is return a redirect (301) to your final image pixel. In this case:
Redirect 301 THE_FB_URL/?id=PIXEL_ID&ev=myCustomEvent&noscript=1
If you're using CFlocation then no, the scripts will not fire. Instead use a javascript relocation. Give the browser enough time to load the page and fire off the script. Something like so:
<script>
fbq('init', 'PIXEL_ID');
fbq('trackCustom', 'myCustomEvent', {});
setTimeout(
function(){
window.location.href='';
// or simply: history.go(-1);
},
3000
);
</script>
<noscript>
<img src="THE_FB_URL/?id=PIXEL_ID&ev=myCustomEvent&noscript=1">
</noscript>

How do clients handle JavaScript after they receive the "Location" HTTP header?

Consider the code:
somepage.php
<?php header('Location: index.php'); ?>
<!DOCTYPE html>
<html>
<head>
<script>
doSomething(); // does the browser run this?
</script>
</head>
</html>
I am trying to put Google Analytics there, but I am not sure if people are actually loading the analytics JS at all.
Does the browser actually look at the output after the Location header has been sent? If so, does it actually run the JavaScript?
Most browsers ignore the response body when a redirect header is sent. So it won't display HTML, and it won't execute Javascript.
If you want to execute something before redirecting, don't use the Location: header. Send a page that executes the Javascript, and then executes
window.location.href = "index.php";

"Add to cart" button not working virtuemart 2 - joomla 2.5

I have recently moved my site from a local server to a test server on-line. I noticed when I made the change, my "Add to cart" button stopped working. I know if has something to do with conflicting javascript or Ajax. I really need to get this fixed please help.
Here is the link to the TEST site.
http://mackeyshotrods.com/test/store/rvca-detail
Its because of the same origin policy viloation
add the below code to your server side ie. php page
<?php
header('Content-Type: application/x-www-form-urlencoded');
header("Access-Control-Allow-Origin: *");
?>
This problem was occurring for me because the .htaccess was directing to 'http://www.mywebsite.com' (i.e. with www. prefix) and virtuemart/security/'security site url' and 'secure url' were set as 'http://mywebsite.com' (i.e. without www. prefix). Thus causing the same origin policy issue. Changing the virtuemart/security/'security site url' and 'secure url' to 'http://www.mywebsite.com' (so they matched) fixed this problem for me.

How to break out of an iFrame when a pop up is in front?

My site has been copied via an iframe and I can't break out, I think because there is a popup infront of the iframe.
This site http:// facebvook . info/claim.html (I broke the link so they don't get a backlink) is the offending site, my site is visible behind the popup.
I've tried the following javascript in my header:
if (top != self) {
top.location.replace(document.location)
alert('busting you out, please wait...')
}
But it doesn't work.
What I ideally want is for my site not to load in the iframe at all, but any other soloution would be good too.
You can send the X-Frame-Options header with a value of 'SAMEORIGIN' to prevent other sites from embedding your site.
In PHP you can do that like this:-
<?php header( 'X-Frame-Options: SAMEORIGIN' ); ?>
Or if you have mod_headers enabled you can create an .htaccess file in your document root with the following text:-
Header always append X-Frame-Options SAMEORIGIN

Categories