undefined
Skip to content
Moz logo Menu open Menu close
  • Products
    • Moz Pro
    • Moz Pro Home
    • Moz Local
    • Moz Local Home
    • STAT
    • Moz API
    • Moz API Home
    • Compare SEO Products
    • Moz Data
  • Free SEO Tools
    • Domain Analysis
    • Keyword Explorer
    • Link Explorer
    • Competitive Research
    • MozBar
    • More Free SEO Tools
  • Learn SEO
    • Beginner's Guide to SEO
    • SEO Learning Center
    • Moz Academy
    • MozCon
    • Webinars, Whitepapers, & Guides
  • Blog
  • Why Moz
    • Digital Marketers
    • Agency Solutions
    • Enterprise Solutions
    • Small Business Solutions
    • The Moz Story
    • New Releases
  • Log in
  • Log out
  • Products
    • Moz Pro

      Your all-in-one suite of SEO essentials.

    • Moz Local

      Raise your local SEO visibility with complete local SEO management.

    • STAT

      SERP tracking and analytics for enterprise SEO experts.

    • Moz API

      Power your SEO with our index of over 44 trillion links.

    • Compare SEO Products

      See which Moz SEO solution best meets your business needs.

    • Moz Data

      Power your SEO strategy & AI models with custom data solutions.

    Track AI Overviews in Keyword Research
    Moz Pro

    Track AI Overviews in Keyword Research

    Try it free!
  • Free SEO Tools
    • Domain Analysis

      Get top competitive SEO metrics like DA, top pages and more.

    • Keyword Explorer

      Find traffic-driving keywords with our 1.25 billion+ keyword index.

    • Link Explorer

      Explore over 40 trillion links for powerful backlink data.

    • Competitive Research

      Uncover valuable insights on your organic search competitors.

    • MozBar

      See top SEO metrics for free as you browse the web.

    • More Free SEO Tools

      Explore all the free SEO tools Moz has to offer.

    NEW Keyword Suggestions by Topic
    Moz Pro

    NEW Keyword Suggestions by Topic

    Learn more
  • Learn SEO
    • Beginner's Guide to SEO

      The #1 most popular introduction to SEO, trusted by millions.

    • SEO Learning Center

      Broaden your knowledge with SEO resources for all skill levels.

    • On-Demand Webinars

      Learn modern SEO best practices from industry experts.

    • How-To Guides

      Step-by-step guides to search success from the authority on SEO.

    • Moz Academy

      Upskill and get certified with on-demand courses & certifications.

    • MozCon

      Save on Early Bird tickets and join us in London or New York City

    Unlock flexible pricing & new endpoints
    Moz API

    Unlock flexible pricing & new endpoints

    Find your plan
  • Blog
  • Why Moz
    • Digital Marketers

      Simplify SEO tasks to save time and grow your traffic.

    • Small Business Solutions

      Uncover insights to make smarter marketing decisions in less time.

    • Agency Solutions

      Earn & keep valuable clients with unparalleled data & insights.

    • Enterprise Solutions

      Gain a competitive edge in the ever-changing world of search.

    • The Moz Story

      Moz was the first & remains the most trusted SEO company.

    • New Releases

      Get the scoop on the latest and greatest from Moz.

    Surface actionable competitive intel
    New Feature

    Surface actionable competitive intel

    Learn More
  • Log in
    • Moz Pro
    • Moz Local
    • Moz Local Dashboard
    • Moz API
    • Moz API Dashboard
    • Moz Academy
  • Avatar
    • Moz Home
    • Notifications
    • Account & Billing
    • Manage Users
    • Community Profile
    • My Q&A
    • My Videos
    • Log Out

The Moz Q&A Forum

  • Forum
  • Questions
  • Users
  • Ask the Community

Welcome to the Q&A Forum

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

  1. Home
  2. SEO Tactics
  3. Technical SEO
  4. 301 redirect syntax for htaccess

Moz Q&A is closed.

After more than 13 years, and tens of thousands of questions, Moz Q&A closed on 12th December 2024. Whilst we’re not completely removing the content - many posts will still be possible to view - we have locked both new posts and new replies. More details here.

301 redirect syntax for htaccess

Technical SEO
3
3
8.6k
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as question
Log in to reply
This topic has been deleted. Only users with question management privileges can see it.
  • SamKlep
    SamKlep last edited by Mar 14, 2018, 11:42 AM

    I'm working on some htaccess redirects for a few stray pages and have come across a few different varieties of 301s that are confusing me a bit....Most sources suggest:

    Redirect 301 /pageA.html http://www.site.com/pageB.html

    or using some combination of:

    RewriteRule + RewriteCond + RegEx

    I've also found examples of:

    RedirectPermanent /pageA.html http://www.site.com/pageB.html

    I'm confused because our current htaccess file has quite a few (working) redirects that look like this:

    Redirect permanent /pageA.html http://www.site.com/pageB.html

    This syntax seems to work, but I'm yet to find another Redirect permanent in the wild, only examples of Redirect 301 or RedirectPermanent

    Is there any difference between these? Would I benefit at all from replacing Redirect permanent with Redirect 301?

    1 Reply Last reply Reply Quote 1
    • IOHanna
      IOHanna last edited by Jun 24, 2019, 9:03 AM Jun 24, 2019, 9:03 AM

      There  is no difference between "Redirect 301", "Redirect permanent" and  "RedirectPermanent". It is clear from mod Alias documentation:

      "This directive makes the client know that the Redirect is permanent (status 301). Exactly equivalent to Redirect permanent."   "permanent - Returns a permanent redirect status (301) indicating that the resource has moved permanently."

      But, these directives are really confusing, because they are not page to page, but directory to directory.  For example:

      Redirect 301 /a-very-old-post/ http://yoursite.com/a-very-new-post/

      Surprisingly, it will redirect all old subpages to new subpages. In particular it will redirect  /a-very-old-post/page1 to /a-very-new-post/page1  Therefore better to use RedirectMatch or RewriteCond+RewriteRule for page by page redirections and for redirections with query strings.

      Links to docs: https://docs.oracle.com/cd/B14099_19/web.1012/q20206/mod/mod_alias.html

      Link to simple RedirectMatch page by page redirects generator: RedirectMatch generator for htaccess https://www.301-redirect.online/htaccess-redirectmatch-generator

      Link to good RewriteRule generator: htaccess 301 redirect rewrite generator https://www.301-redirect.online/htaccess-rewrite-generator

      1 Reply Last reply Reply Quote 0
      • topic:timeago_earlier,about a year
      • BlueprintMarketing
        BlueprintMarketing last edited by Mar 16, 2018, 6:25 PM Mar 14, 2018, 9:49 PM

        In **apache **"permanent" "RedirectPermanent" is  the same as "Redirect 301"

        By default, the "Redirect" directive establishes a 302, or temporary, redirect.

        If you would like to create a permanent redirect, you can do so in either of the following two ways:

        1. Redirect 301 /oldlocation http://www.domain2.com/newlocation
        2. Redirect permanent /oldlocation http://www.domain2.com/newlocation
        • See
        • https://www.digitalocean.com/community/tutorials/how-to-create-temporary-and-permanent-redirects-with-apache-and-nginx

        Page to Page 301 Redirect Generator for Htaccess

        https://www.aleydasolis.com/htaccess-redirects-generator/

        If no <var>status</var> argument is given, the redirect will be "temporary" (HTTP status 302). This indicates to the client that the resource has moved temporarily. The <var>status</var> argument can be used to return other HTTP status codes:

        <dl> "permanent" & "Redirect 301"</dl>

        <dl>

        <dd>Returns a permanent redirect status (301) indicating that the resource has moved permanently.</dd>

        "temp"</dl>

        <dl>

        <dt>Returns a temporary redirect status (302). This is the default.</dt>

        "seeother"</dl>

        <dl>

        <dd>Returns a "See Other" status (303) indicating that the resource has been replaced.</dd>

        "gone"</dl>

        <dl>

        <dd>Returns a "Gone" status (410) indicating that the resource has been permanently removed. When this status is used the <var>URL</var> argument should be omitted.</dd>

        </dl>

        **https://httpd.apache.org/docs/2.4/mod/mod_alias.html **

        https://www.askapache.com/htaccess/seo-search-engine-friendly-redirects-without-mod_rewrite/#seo-301-redirect-single-file

        https://www.bruceclay.com/blog/how-to-properly-implement-a-301-redirect/

        To 301 Redirect a Page:

        RedirectPermanent /old-file.html http://www.domain.com/new-file.html

        To 301 Redirect a Page:

        Redirect 301 /old-file.html http://www.domain.com/new-file.html

        https://i.imgur.com/PTEj5ZF.png

        https://www.aleydasolis.com/htaccess-redirects-generator/

        Single URL redirect

        Permanent redirect from pageA_.html_ to pageB.html.

        .htaccess:

        301 Redirect URLs.

        Redirect 301 /pageA.html http://www.site.com/pageB.html

        https://www.aleydasolis.com/htaccess-redirects-generator/page-to-page/

        <ifmodule mod_rewrite.c="">RewriteEngine On
        Redirect 301 /pageA.html /pageB.html</ifmodule>

        https://www.htaccessredirect.net/

        //Rewrite to www
        Options +FollowSymLinks
        RewriteEngine on
        RewriteCond %{HTTP_HOST} ^site.com[nc]
        RewriteRule ^(.*)$ http://www.site.com/$1 [r=301,nc]

        //301 Redirect Old File
        Redirect 301 /pageA.html /pageB.html

        You asked about Regex

        https://mediatemple.net/community/products/dv/204643270/using-htaccess-rewrite-rules

        .htaccess

        Regular expressions

        Rewrite rules often contain symbols that make a regular expression (regex). This is how the server knows exactly how you want your URL changed. However, regular expressions can be tricky to decipher at first glance. Here's some common elements you will see in your rewrite rules, along with some specific examples.

        • ^ begins the line to match.
        • $ ends the line to match.
          • So, ^folder1$ matches folder1 exactly.
        • . stands for "any non-whitespace character" (example: a, B, 3).
        • * means that the previous character can be matched zero or more times.
          • So, ^uploads.*$ matches uploads2009, uploads2010, etc.
          • ^.*$ means "match anything and everything." This is useful if you don't know what your users might type for the URL.
        • () designates which portion to preserve for use again in the $1 variable in the second string. This is useful for handling requests for particular files that should be the same in the old and new versions of the URL.

        See for more regex

        • http://perldoc.perl.org/perlre.html#Regular-Expressions
        • https://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet/
        • https://www.askapache.com/htaccess/

        Hope this helps

        Tom

        PTEj5ZF.png

        1 Reply Last reply Reply Quote 2
        • 1 / 1
        1 out of 3
        • First post
          1/3
          Last post

        Got a burning SEO question?

        Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.


        Start my free trial


        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.

        • See all categories

        Related Questions

        • moz46y

          Reusing an already 301 redirected URL for a very important keyword

          301 redirect 301 redirects

          I have a question about reusing an already 301 redirected URL Till now I never reused an URLs that has been already redirected with a 301 redirect. However, I just started working on a website where in past they created a lot of 301 redirects without thinking about the future, and now certain URLs, that are currently redirected with a 301, would be very useful (exact match) and needed (for some of the most important keywords for this specific business), to maintain an optimal, homogeneous and "beautiful" URL structure. Has any of you ever reused a URL that was previously redirected with a 301 redirect? If yes what are your experiences with it? Can content on the reused URL (that was previously 301 redirected and than the redirect removed) normally rank if the page is reestablished and the redirect is removed (and you do great content, on page, internal linking, backlinking, .... ) or is such an URL risky / not recommended / "burned" forever and not recommended to be reused again... especially for very important keywords since it present the exact match ?! Thank you very much for all your help! Regards

          Technical SEO | Jan 23, 2024, 5:39 PM | moz46y
          0
        • Damian_Ed 0

          Unsolved Temporary redirect from 302 to 301 for PNG File?

          302 temporary riderect 301 http status image issue

          #302HTTP #temporaryredirect
          Hi everyone, Recently I have faced a crawl issue with my media images on website. For example this page url https://intreface.com/wp-content/uploads/2022/12/Horion-screen-side-2.png has 302 HTTP Status and the recommendation is to change it 301. I have read the article on temporary redirections here:
          https://moz.com/learn/seo/redirection?_ga=2.45324708.1293586627.1702571936-916254120.1702571936
          but its not written here how to redirect in my HTML 1 image url not the landing page.
          Screenshot 2023-12-15 at 11.02.40.png
          I have messaged to MOZ Support but they recommended to go for the MOZ Community!
          Screenshot 2023-12-15 at 11.06.02.png Could you assist me wit this issue please? I can reach HTTML of the necessary page and change what I need for permanent redirection but firstly I need to understand how to do that correctly.

          Technical SEO | Jan 23, 2024, 5:26 AM | Damian_Ed 0
          0
        • CitimarineMoz

          How effective are 301 redirects in passing page rank?

          301 redirect page rank

          I have a blog which is ranking well for certain terms, and would like to repurpose it to better explain these terms it is ranking for, including updating the url to the new term the blog will be about. The plan being to 301 redirect the old url to new. In the past, I've done this with other pages, and have actually lost much of the rankings that I had earned on the original URL. What is your take on this? Maybe repurpose blog, but maintain original URL just to be on the safe side? Thanks

          Technical SEO | May 22, 2022, 1:51 PM | CitimarineMoz
          0
        • TaraLP

          Delete old blog posts after 301 redirects to new pages?

          Hi Moz Community, I've recently created several new pages on my site using much of the same copy from blog posts on the same topics (we did this for design flexibility and a few other reasons). The blogs and pages aren't exactly identical, as the new pages have much more content, but I don't think there's a point to having both and I don't want to have duplicate content, so we've used 301 redirects from the old blog posts to the new pages of the same topic. My question is: can I go ahead and delete the old blog posts? (Or would there be any reasons I shouldn't delete them?) I'm guessing with the 301 redirects, all will be well in the world and I can just delete the old posts, but I wanted to triple check to make sure. Thanks so much for your feedback, I really appreciate it!

          Technical SEO | Oct 4, 2019, 2:20 PM | TaraLP
          1
        • LindsayE

          What to do with old content after 301 redirect

          I'm going through all our blog and FAQ pages to see which ones are performing well and which ones are competing with one another. Basically doing an SEO content clean up. Is there any SEO benefit to keeping the page published vs trashing it after you apply a 301 redirect to a better performing page?

          Technical SEO | Dec 8, 2017, 11:20 AM | LindsayE
          0
        • Silviu

          301 redirect relative or absolute path?

          Hello everyone, Recently we've changed the URL structure on our website, and of course we had to 301 redirect the old urls to the coresponding new ones. The way the technical guys did this is: "http://www.domain.com/old-url.html" 301 redirect to "/new-url.html"
          meaning as a relative redirect path, not an absolute one like this:
          "http://www.domain.com/old-url.html" 301 redirect to "http://www.domain.com/new-url.html" This happened for few thousands urls, and the fact is the organic traffic dropped for those pages after this change. (no other changes were made on these pages and the new urls are as seo friendly as possible, A grade on On-Page Grader). The question is: does the relative redirect negatively affects seo, or it counts the same as an absolute path redirect? Thanks,
          S.

          Technical SEO | Oct 24, 2013, 7:01 AM | Silviu
          0
        • Natitude

          Best Practice on 301 Redirect - Images

          We have two sites that sell the same products. We have decided to retire one of the sites as we'd like to focus on one property. I know best practice is to redirect apples to apples, which in our case is easily done since the sites sold the same thing. www.SiteABC.com/ProductA can be redirected to www.SiteXYZ.com/ProductA. My question is how far does that thinking go regarding images? Each product has a main product page, of course, and then up to 6 images in some cases. Is it necessary to redirect www.SiteABC.com/ProductA-Image1.jpg to www.SiteXYZ.com/ProductA-Image1.jpg? Or can they all be redirected to just the product page?

          Technical SEO | Aug 16, 2013, 2:45 AM | Natitude
          0
        • sboelter

          Multiple Domains, Same IP address, redirecting to preferred domain (301) -site is still indexed under wrong domains

          Due to acquisitions over time and the merging of many microsites into one major site, we currently have 20+ TLD's  pointing to the same IP address as our "preferred domain:"  for our consolidated website http://goo.gl/gH33w. They are all set up as 301 redirects on apache - including both the www and non www versions. When we launched this consolidated website, (April 2010) we accidentally left the settings of our site open to accept any of our domains on the same IP.  This was later fixed but unfortunately Google indexed our site under multiple of these URL's (ignoring the redirects) using the same content from our main website but swapping out the domain.  We added some additional redirects on apache to redirect these individual pages pages indexed under the wrong domain to the same page under our main domain http://goo.gl/gH33w.  This seemed to help resolve the issue and moved hundreds of pages off the index.  However, in December of 2010 we made significant changes in our external dns for our ip addresses and now since December, we see pages indexed under these redirecting domains on the rise again. If you do a search query of : site:laboratoryid.com you will see a few hundred examples of pages indexed under the wrong domain.  When you click on the link, it does redirect to the same page but under the preferred domain.  So the redirect is working and has been confirmed as 301.  But for some reason Google continues to crawl our site and index under this incorrect domains.  Why is this? Is there a setting we are missing?   These domain level and page level redirects should be decreasing the pages being indexed under the wrong domain but it appears it is doing the reverse. All of these old domains currently point to our production IP address where are preferred domain is also pointing.  Could this be the issue? None of the pages indexed today are from the old version of these sites. They only seem to be the new content from the new site but not under the preferred domain. Any insight would be much appreciated because we have tried many things without success to get this resolved.

          Technical SEO | Jun 2, 2011, 3:45 PM | sboelter
          0

        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 - 2025 SEOMoz, Inc., a Ziff Davis company. All rights reserved. Moz is a registered trademark of SEOMoz, Inc.
        • Accessibility
        • Terms of Use
        • Privacy

        Looks like your connection to Moz was lost, please wait while we try to reconnect.