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
-
301 Redirects a Year Later
I inherited the digital maintenance of a website that was relaunched a year ago. In looking at Google Analytics, organic search a year later is still down 33%. I fear they did not install 301 Redirects but can't really get a specific answer from them. Is it possible to install them a year later to help with Google indexing and get back some of the organic traffic?
Technical SEO | | stansamples0 -
Console: Change Of Address, 301 Redirects Step Not Working
Hi everyone, We just made a switch to a new domain based on a rebrand, and we are currently directing users who navigate to the homepage of the old site to an interim page on our new site that reads companyname.com/companyname, that then redirects to the actual homepage of the new site, companyname.com. The redirect page's purpose is to tell users about the brand name change before showing them the new site. The challenge is that in the second step of the verification process for the address change, it reads that our domain name request does not correspond because the homepage is directing to this interim page. Is there a way for us to continue to direct people to companyname.com/companyname and have GSC verify that the 301 redirects work properly? Ideally we would not want to direct people from the homepage of the old site to the homepage of the new site. Thank you in advance for your help. Sincerely, Chase VHSpF
Technical SEO | | commcreative0 -
Selective 301 redirections of pages within folders
Redirection Puzzle - it's got me puzzled anyhow! The finished website has just been converted from an old aspx affair to a wordpress site. Some directory structures have changed significantly; there appears to be a load of older medical articles that have not been added back in and it sounds unlikely that they will be. Therefore unmatched old news articles need to be pointed to the top news page to keep hold of any link value they may have accrued. The htaccess file starts with ithemes security's code, Followed by the main wordpress block and I have added the user redirects to the final section of the htaccess file . I have been through the redirects and rewrites line by line to verify them and the following sections are giving me problems. This is probably just my aging brain failing to grasp basic logic. If I can tap into anybody's wisdom for a bit of help I would appreciate it. My eyes and brain are gone to jelly. I have used htaccesscheck.com to check out the underlying syntax and ironed out the basic errors that I had previously missed. The bulk of the redirects are working correctly. #Here there are some very long media URLs which are absent on the new site and I am simply redirecting visiting spiders to the page that will hold media in future. Media items refuse to redirect
Technical SEO | | TomVolpe
Line 408 redirect 301 /Professionals/Biomedicalforum/Recordedfora/Rich%20Media%20http:/kplayer.kcl.ac.uk/ess/echo/presentation/15885525-ff02-4ab2-b0b9-9ba9d97ca266 http://www.SITENAME.ac.uk/biomedical-forum/recorded-fora/ Line 409 redirect 301 /Professionals/Biomedicalforum/Recordedfora/Quicktime%20http:/kplayer.kcl.ac.uk/ess/echo/presentation/15885525-ff02-4ab2-b0b9-9ba9d97ca266/media.m4v http://www.SITENAME.ac.uk/biomedical-forum/recorded-fora/ Line 410 redirect 301 /Professionals/Biomedicalforum/Recordedfora/Mp3%20http:/kplayer.kcl.ac.uk/ess/echo/presentation/15885525-ff02-4ab2-b0b9-9ba9d97ca266/media.mp3 http://www.SITENAME.ac.uk/biomedical-forum/recorded-fora/ #Old site pagination URLs redirected to new "news" top level page - Here I am simply pointing all the pagination URLs for the news section, that were indexed, to the main news page. These work but append the pagination code on to the new visible URL. Have I got the syntax correct in this version of the lines to suppress the appended garbage? RewriteRule ^/LatestNews.aspx(?:.*) http://www.SITENAME.ac.uk/news-events/latest-news/? [R=301,L] #On the old site many news directories (blog effectively) contained articles that are unmatched on the new site, have been redirected to new top level news (blog) page: In this section I became confused about whether to use Redirect Match or RewriteRule to point the articles in each year directory back to the top level news page. When I have added a redirectmatch command - it has been disabling the whole site! Despite my syntax check telling me it is syntactically correct. Currently I'm getting a 404 for any of the old URLs in these year by year directories, instead of a successful redirect. I suspect Regex lingo is not clicking for me 😉 My logic here was rewrite any aspx file in the directory to the latest news page at the top. This is my latest attempt to rectify the fault. Am I nearer with my syntax or my logic? The actual URLs and paths have been substituted, but the structure is the same). So what I believe I have set up is: in an earlier section; News posts that have been recreated in the new site are redirected 1 - 1 and they are working successfully. If a matching URL is not found, when the parsing of the file reaches the line for the 1934 directory it should read any remaining .aspx URL request and rewrite it to the latest news page as a 301 and stop processing this block of commands. The subsequent commands in this block repeat the process for the other year groups of posts. Clearly I am failing to comprehend something and illumination would be gratefully received. RewriteRule ^/Blab/Blabbitall/1934/(.*).aspx http://www.SITENAME.ac.uk/news-events/latest-news/ [R=301,L] #------Old site 1933 unmatched articles redirected to new news top level page RewriteRule ^/Blab/Blabbitall/1933/(.*).aspx http://www.SITENAME.ac.uk/news-events/latest-news/ [R=301,L] #------Old site 1932 unmatched articles redirected to new news top level page RewriteRule ^/Blab/Blabbitall/1932/(.*)/.aspx http://www.SITENAME.ac.uk/news-events/latest-news/ [R=301,L] #------Old site 1931 unmatched articles redirected to new news top level page RewriteRule ^/Blab/Blabbitall/1931/(.*)/.aspx http://www.SITENAME.ac.uk/news-events/latest-news/ [R=301,L] #------Old site 1930 unmatched articles redirected to new news top level page RewriteRule ^/Blab/Blabbitall/1930/(.*)/.aspx http://www.SITENAME.ac.uk/news-events/latest-news/ [R=301,L] Many thanks if anyone can help me understand the logic at work here.0 -
301 Redirect back to original domain
We have a site, domainA.com and we split part of the site off into it's own site a couple of years ago as domainB.com. All urls from DomainA were 301 redirected to DomainB, but with a different folder structure. For business reasons, we now shuttering domainB and rolling it back into domainA. For the 301 redirects for urls that were on the original domainA, should I overwrite them to the new folder structure directly from the original urls? In other words: 301 redirect domainA.com/oldstructure to domainA.com/newstructure rather than: Existing 301 redirect domainA.com/oldstructure to domainB.com/newstructuretopic with a new 301 redirect to domainA.com/newstructuretopictopic
Technical SEO | | ang0 -
Updating inbound links vs. 301 redirecting the page they link to
Hi everyone, I'm preparing myself for a website redesign and finding conflicting information about inbound links and 301 redirects. If I have a URL (we'll say website.com/website) that is linked to by outside sources, should I get those outside sources to update their links when I change the URL to website.com/webpage? Or is it just as effective from a link juice perspective to simply 301 redirect the old page to the new page? Are there any other implications to this choice that I may want to consider? Thanks!
Technical SEO | | Liggins0 -
Instead of a 301, my client uses a 302 to custom 404
I've found about 900 instances of decommissioned pages being redirected via 302 to a 404 custom page, even when there's a comparable page elsewhere on the site or on a new subdomain. My recommendation would be to always do a 301 from the legacy page to the new page, but since they're are so many instances of this 302->404 it seems to be standard operating procedure by the dev team. Given that at least one of these pages has links coming from 48 root domains, wouldn't it obviously be much better to 301 redirect it to pass along that equity? I don't get why the developers are doing this, and I have to build a strong case about what they're losing with this 302->404 protocol. I'd love to hear your thoughts on WHY the dev team has settled on this solution, in addition to what suffers as a result. I think I know, but would love some more expert input.
Technical SEO | | Jen_Floyd0 -
301 Redirect on a PDF, DOCX files?
Hi, I have to rename many pdf and docx files. How can I implement 301 redirect on them as they are linked from 'n' number of places? Regards, Shailendra Sial
Technical SEO | | IM_Learner1 -
Using DNS & 301 redirects to gain control over a rogue site
I'd appreciate peoples' views on the following please. We have been approached by a client whose website does not rank # 1 for their own distinctive brand name due to this position being taken by a site they had developed for them by an affiliate some years back. The affiliate's site is clearly seen by Google as the definitive site for the brand - being older, having more links & in both Yahoo & DMOZ. The relationship has soured with the affiliate & the client wants to take control of the affiliate site & have it 301 redirect to the 'real' brand site. The affiliate won't cooperate (funny that). However whilst the client doesn't have control over the affiliate's website, they do own the domain. Given this, it seems that an option is to temporarily create a 1 page website on another server, change the affiliate website domain DNS settings to point to this, & in turn have that 301 re-direct to the client's website. This is a bit of a round about approach, but necessary because the affiliate won't directly 301 the site they control - despite the client owning it. (As I say the relationship has soured). If you think there's a better alternative approach to this problem (aside from litigation), I'd appreciate hearing it please. Thanks.
Technical SEO | | SureFire0