The Moz Q&A Forum

    • Forum
    • Questions
    • My Q&A
    • Users
    • Ask the Community

    Welcome to the Q&A Forum

    Browse the forum for helpful insights and fresh discussions about all things SEO.

    1. SEO and Digital Marketing Q&A Forum
    2. Categories
    3. Technical SEO Issues
    4. 301 redirect using javascript

    301 redirect using javascript

    Technical SEO Issues
    6 4 35.3k
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as question
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Alick300
      Alick300 last edited by

      Can I use javascript code to redirect(301) a webpage?

      1 Reply Last reply Reply Quote 0
      • timhatton
        timhatton last edited by

        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.

        Alick300 1 Reply Last reply Reply Quote 0
        • Alick300
          Alick300 @timhatton last edited by

          I have a html site,I cant use server side scripting languages.So in your opinion how to redirect html site?

          timhatton 1 Reply Last reply Reply Quote 0
          • timhatton
            timhatton @Alick300 last edited by

            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...

            1 Reply Last reply Reply Quote 0
            • donford
              donford last edited by

              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

              1 Reply Last reply Reply Quote 0
              • lcallander
                lcallander last edited by

                I did this on my wordpress site.  Here are my instructions:

                https://moz.com/community/q/switched-from-wix-to-wordpress-dreaded-hashtag-url

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                • Redirection chain and Javascript Redirect
                  0
                  1
                  19

                • Pages with 301 redirects showing as 200 when crawled using RogerBot
                  matthew.dimmett
                  matthew.dimmett
                  0
                  3
                  211

                • Redirect a 301 Redirect
                  RedCaffeine
                  RedCaffeine
                  0
                  5
                  98

                • Ideally should a 301 or 302 redirect be used from https://www.site.com to http://www.site.com? Is there a valid reason to use a 302 in this situation or would using a 301 have any negative impact on seo?
                  Unity
                  Unity
                  0
                  2
                  317

                • What factors matters the most when using a 301 permanent redirect?
                  BenFox
                  BenFox
                  0
                  2
                  349

                • 301 Redirect & re-use
                  mediabase
                  mediabase
                  0
                  3
                  837

                • Using DNS & 301 redirects to gain control over a rogue site
                  SureFire
                  SureFire
                  0
                  3
                  794

                • Should I 301 redirect my country specific sites, or use them as linking root domains?
                  jcarter
                  jcarter
                  0
                  3
                  1.3k

                Get started with Moz Pro!

                Unlock the power of advanced SEO tools and data-driven insights.

                Start my free trial
                Products
                • Moz Pro
                • Moz Local
                • Moz API
                • Moz Data
                • STAT
                • Product Updates
                Moz Solutions
                • SMB Solutions
                • Agency Solutions
                • Enterprise Solutions
                • Digital Marketers
                Free SEO Tools
                • Domain Authority Checker
                • Link Explorer
                • Keyword Explorer
                • Competitive Research
                • Brand Authority Checker
                • Local Citation Checker
                • MozBar Extension
                • MozCast
                Resources
                • Blog
                • SEO Learning Center
                • Help Hub
                • Beginner's Guide to SEO
                • How-to Guides
                • Moz Academy
                • API Docs
                About Moz
                • About
                • Team
                • Careers
                • Contact
                Why Moz
                • Case Studies
                • Testimonials
                Get Involved
                • Become an Affiliate
                • MozCon
                • Webinars
                • Practical Marketer Series
                • MozPod
                Connect with us

                Contact the Help team

                Join our newsletter
                Moz logo
                © 2021 - 2026 SEOMoz, Inc., a Ziff Davis company. All rights reserved. Moz is a registered trademark of SEOMoz, Inc.
                • Accessibility
                • Terms of Use
                • Privacy