I have an
<a></a> tag with
href to a specified location and I'm asked to make a 301 redirect when I click that link.
This is for SEO and I'm trying to find a way to do the 301 redirect to the same page in the link without having to create a new page or create a form/submit.
In short No.
I know this is an old question but the answers don't really address the primary issue that was presented in the question which is a 301 redirect for SEO purposes (and the answer today may very well be different than it was when the question was originally asked and answered).
The answer that no, you can't 301 redirect from the client is technically correct, however (and more importantly) you don't necessarily need to. While a true 301 would be preferred, in cases like this one where it's not possible (or transitioning away from hashbang URLs back to traditional URLs for example), the question is really whether or not there's a viable alternative that accomplishes the goal.
Result: The redirects were quickly followed by Google. From an indexing standpoint, they were interpreted as 301s — the end-state URLs replaced the redirected URLs in Google’s index.
301 is a server response code. You would not be able to create a 301 redirect from jQuery.
You'll have to do the 301 from PHP.
Instead you can actually put in href the final URL if you cannot do it on the server.
Or, if you're asking if you can redirect the current page, yes it's possible with META redirects or by changing the window.location.
If you're using Apache you can use mod_rewrite to do a 301 redirect.
If this is for SEO purpose only then this will work
<meta http-equiv="refresh" content="0;url=YOUR_URL">
Google considers this as a 301 redirect though it's not
©2020 All rights reserved.