301 redirect using javascript
-
Can I use javascript code to redirect(301) a webpage?
-
I did this on my wordpress site. Here are my instructions:
https://moz.com/community/q/switched-from-wix-to-wordpress-dreaded-hashtag-url
-
Hi GenSEO..
301 is a server response code and handled by the server on linux / unix systems usually via htaccess if you have access to the server then you would use this method, unless its a IIS server (Windows) in which case its a little different.
You can test your server package if you don't know what server you're on..
PHP for Linux / Unix / Apache put this at the very top of the page
ASP for Windows Servers
`<%@ Language=VBScript %> <% ' Permanent redirection Response.Status = "301 Moved Permanently" Response.AddHeader "Location", "http://``www.mysite.com/new-page.html``/" Response.End %>`
That said, the best option if you do not have access to the server is to use a META refresh, some search engines will treat this as 30x redirect, by placing this at the top of the page
HTML Page Redirect -
Are they literally just flat HTML files - not served from a CMS or anything?
Do you know what kind of server you are on? You can probably find out here http://news.netcraft.com/ (box top left)
If you're on Apache, then see if you can edit your .htaccess file - this should be in the root of your web space. Note: editing .htaccess can seriously muck up your site if you get it wrong. It depends what kind of redirect you want to do, but if you're just looking to redirect abc.html to xyz.html then you'd add in a line like this:
redirect 301 /abc.html /xyz.html
If you're on IIS I'd have to bow to someone with better knowledge of IIS...
-
I have a html site,I cant use server side scripting languages.So in your opinion how to redirect html site?
-
No, Javascript is run at the client (browser) side and a 301 has to be done server side.
However, it's really quite simple to do using PHP or ASP - have a look at http://www.webconfs.com/how-to-redirect-a-webpage.php which gives sample code for various languages.
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
Browse Questions
Explore more categories
-
Moz Tools
Chat with the community about the Moz tools.
-
SEO Tactics
Discuss the SEO process with fellow marketers
-
Community
Discuss industry events, jobs, and news!
-
Digital Marketing
Chat about tactics outside of SEO
-
Research & Trends
Dive into research and trends in the search industry.
-
Support
Connect on product support and feature requests.
Related Questions
-
After you remove a 301 redirect that Google has processed, will the new URL retain any of the link equity from the old URL?
Lets say you 301 redirect URL A to URL B, and URL A has some backlinks from other sites. Say you left the 301 redirect in place for a year, and Google had already replaced the old URL with the new URL in the SERPs, would the new URL (B) retain some of the link equity from URL A after the 301 redirect was removed, or does the redirect have to remain in place forever?
Technical SEO | | johnwalkersmith0 -
Redirect 301 to homepage
Hello there, I have some low quality pages in my site, can I redirect 301 them to my homepage? My website is: https://idanito.com idanito.com
Technical SEO | | dannybaldwin0 -
Pages with 301 redirects showing as 200 when crawled using RogerBot
Hi guys, I recently did an audit for a client and ran a crawl on the site using RogerBot. We quickly noticed that all but one page was showing as status code 200, but we knew that there were a lot of 301 redirects in place. When our developers checked it, they saw the pages as 301s, as did the Moz toolbar. If page A redirected to page B, our developers and the Moz toolbar saw page A as 301 and page B as 200. However the crawl showed both page A and page B as 200. Does anyone have any idea why the crawl may have been showing the status codes as 200? We've checked and the redirect is definitely in place for the user, but our worry is that there could be an issue with duplicate content if a crawler isn't picking up on the 301 redirect. Thanks!
Technical SEO | | Welford-Media0 -
Existing content & 301 redirects
Hi All, I will try to keep this to the point. One of our websites was hit by penguin for unnatural linking. We are building a new site (same business, different domain), but we would like to take some of the pages/content off the old website and use it on our new site. Is it just a case of copying each page onto our new site and 301 redirect the old URL? Or should I just be completely rewording/recreating the old content so it is unique? Any help on this would be great, but I am also open to alternate methods too. Thanks Lewis
Technical SEO | | SO_UK0 -
Link juice and 301 redirects
Hi, I have a page with a lot of links going to it. I want to change the name of the page (thereby changing the URL). I can do a 301 redirect, but does a 301 send the "link juice" to the new page? The page in question is www.aerlawgroup.com/dui.html, and I want to change it to www.aerlawgroup.com/dui-lawyer.html. Thank you in advance for your time.
Technical SEO | | mrodriguez14400 -
What factors matters the most when using a 301 permanent redirect?
Hi SEOmozzers, I have a client that has couple of duplicates but I am debating if i should just kill those pages or use 301 Permanent redirects. I know SEO moz provides 2 important factors to look at which are PA and link root domain. 1.Which one matters the most? or which one should I look at first to make a decision? 2. I have empty pages creating duplicate content with a PA of 14 and 1 linking root domain. my thought is to kill the page by inserting a meta NO INDEX. If you don't agree and think I should 301 to an existing page that needs link juice, let me know. Thank you mozzers 🙂
Technical SEO | | Ideas-Money-Art0 -
How to make multiple url redirection using global.asax in IIS 6?
sir, I am working with IIS 6 site and i ant to redirect three different urls of a domain to one url, i.e, there are the different versions of the same url...so how can i create one? I have found a script on google. but it says redirecting one url. see it here: Sub Application_BeginRequest(ByVal sender as Object, ByVal e as EventArgs) Try Dim requestedDomain As String = HttpContext.Current.Request.Url.ToString().toLower() If InStr(requestedDomain, "http://yoursite.com") Then requestedDomain = requestedDomain.Replace("http://yoursite.com", "http://www.yoursite.com") Response.Clear() Response.Status = "301 Moved Permanently" Response.AddHeader("Location", requestedDomain) Response.End() End If Catch ex As Exception Response.Write("Error in Global.asax :" & ex.Message) End Try End Sub
Technical SEO | | VipinLouka780 -
How do 301 redirects affect rankings?
Scenario: example.com/red-shoes gets 301 redirected to example.com/brown-boots because we have stopped selling red shoes and now only sell brown boots (which is a fairly new page with no authority). the red-shoes page ranked well for "red shoes" and "footwear". Will Google still index and show the red-shoes url in the SERPs? Will the "red shoes" and "footwear" keywords still rank well? Or does the redirected/new boots page need to properly support these keywords? The boots page has inherited the juice from the shoes page, but how does it help the boots page rank well? Only for keywords that both pages targeted, like a general "footwear" type keyword? Thanks in advance!
Technical SEO | | akim260