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
      • SEO Q&A
      • Webinars, Whitepapers, & Guides
    • Blog
    • Why Moz
      • Agency Solutions
      • Enterprise Solutions
      • Small Business Solutions
      • Case Studies
      • 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.

      NEW Keyword Suggestions by Topic
      Moz Pro

      NEW Keyword Suggestions by Topic

      Learn more
    • 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.

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

      • SEO Q&A

        Insights & discussions from an SEO community of 500,000+.

      Unlock flexible pricing & new endpoints
      Moz API

      Unlock flexible pricing & new endpoints

      Find your plan
    • Blog
    • Why Moz
      • 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.

      • Case Studies

        Explore how Moz drives ROI with a proven track record of success.

      • 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
    8557
    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

      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

        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
        • BlueprintMarketing
          BlueprintMarketing last edited by

          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
          • First post
            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

          • tejasbansode

            Is 301 redirect the only way when using Vanity URLs?

            We have been using vanity urls for some of our pages. Mostly the pages that have a vanity URL have a long URL length. But now the problem is, the vanity URL is getting displayed on the search engine when the particular keyword related to the page is entered. I checked the google search console, the vanity URL is indexed and the original URL remains unindexed. What should I do? Is adding 301 redirect to the vanity URLs are solution? Since some of vanity URLs are not redirecting to the original. Some of the original pages are not getting traffic. Also, can using canonical tag help?

            Technical SEO | | tejasbansode
            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 | | TaraLP
            1
          • snorkel

            1000 Pages on old website. What to do with the 301 redirects for this domain?

            Hi Moz Community, I have a 301 redirect question... I just acquired an old domain: Totally in my niche Domain is 14 years old Website exists of 1000 pages Great amount of backlinks Website is offline since about 2 weeks Will place a new website online asap with new url structure For the 50 best scoring pages I wrote a new, but fully comparable/related article. I will put a 301 redirect from those old to the new pages. My question: What to do with the 950 other url's? Should I put a 301 redirect to the homepage? Should I forward those pages to the 404 page? Should I divide the 950 url's with a 301 redirect to the 50 new ones? Another solution maybe? Any idea what would be the best solution so we can save as much Google juice as possible? Thanks in advance!

            Technical SEO | | snorkel
            0
          • Direct_Ram

            Blogger /blog Folder level redirect setup using .htaccess

            We have a blog currently powered by the free blogger.com website. We have set it up as blog.example.com we wish to seti it up as example.com/blog how can we do this using .htaccess file? we understand how to update htacess, but we don't know what code we should enter to achieve what we want our website is hosted on Apache servers with plesk control panel

            Technical SEO | | Direct_Ram
            0
          • Houdoe

            CNAME vs 301 redirect

            Hi all, Recently I created a website for a new client and my next job is trying to get them higher in Google. I added them in OSE and noticed some strange backlinks. To my surprise the client has about 20 domain names. All automatically poiting to (showing) the same new mainsite now. www.maindomain.nl www.maindomain.be
            www.maindomain.eu
            www.maindomain.com
            www.otherdomain.nl
            www.otherdomain.com
            ... Some of these domains have backlinks too (but not so much). I suggested to 301 redirect them all to the main site. Just to avoid duplicate content. But now the webhoster comes into play: "It's a problem, client has only 1 hosting account, blablabla...". They told me they could CNAME the 20 domains to the main domain. Or A-record them to an IP address. This is too technical stuff for me. So my concrete questions are: Is it smart to do anything at all or am I just harming my client? The main site is ranking pretty well now. And some backlinks are from their copy sites (probably because everywhere the logo links to the full mainsite url). Does the CNAME or A-record solution has the same effect as a 301 redirect, from SEO perspective? Many thanks,
            Hans

            Technical SEO | | Houdoe
            0
          • ulefos

            Remove html file extension and 301 redirects

            Hi Recently I ask for some work done on my website from a company,  but I am not sure what they've done is right.
            What I wanted was html file extensions to be removed like
            /ash-logs.html to /ash-logs
            also the index.html to www.timports.co.uk
            I have done a crawl diagnostics and have duplicate page content and 32 page title duplicates. This is so doing my head in please help This is what is in the .htaccess file <ifmodule pagespeed_module="">ModPagespeed on
            ModPagespeedEnableFilters extend_cache,combine_css, collapse_whitespace,move_css_to_head, remove_comments</ifmodule> <ifmodule mod_headers.c="">Header set Connection keep-alive</ifmodule> <ifmodule mod_rewrite.c="">Options +FollowSymLinks -MultiViews</ifmodule> DirectoryIndex index.html RewriteEngine On 
             # Rewrite valid requests on .html files  RewriteCond %{REQUEST_FILENAME}.html -f RewriteRule ^ %{REQUEST_URI}.html?rw=1 [L,QSA] 
             # Return 404 on direct requests against .html files RewriteCond %{REQUEST_URI} .html$  
            RewriteCond %{QUERY_STRING} !rw=1 [NC]
             RewriteRule ^ - [R=404] AddCharset UTF-8 .html # <filesmatch “.(js|css|html|htm|php|xml|swf|flv|ashx)$”="">#SetOutputFilter DEFLATE #</filesmatch> <ifmodule mod_expires.c="">ExpiresActive On
            ExpiresByType image/gif "access plus 1 years"
            ExpiresByType image/jpeg "access plus 1 years"
            ExpiresByType image/png "access plus 1 years"
            ExpiresByType image/x-icon "access plus 1 years"
            ExpiresByType image/jpg "access plus 1 years"
            ExpiresByType text/css "access 1 years"
            ExpiresByType text/x-javascript "access 1 years"
            ExpiresByType application/javascript "access 1 years"
            ExpiresByType image/x-icon "access 1 years"</ifmodule> <files 403.shtml="">order allow,deny allow from all</files> redirect 301 /PRODUCTS http://www.timports.co.uk/kiln-dried-logs
            redirect 301 /kindling_firewood.html http://www.timports.co.uk/kindling-firewood.html
            redirect 301 /about_us.html http://www.timports.co.uk/about-us.html
            redirect 301 /log_delivery.html http://www.timports.co.uk/log-delivery.html redirect 301 /oak_boards_delivery.html http://www.timports.co.uk/oak-boards-delivery.html
            redirect 301 /un_edged_oak_boards.html http://www.timports.co.uk/un-edged-oak-boards.html
            redirect 301 /wholesale_logs.html http://www.timports.co.uk/wholesale-logs.html redirect 301 /privacy_policy.html http://www.timports.co.uk/privacy-policy.html redirect 301 /payment_failed.html http://www.timports.co.uk/payment-failed.html redirect 301 /payment_info.html http://www.timports.co.uk/payment-info.html

            Technical SEO | | ulefos
            1
          • Gmorgan

            301 redirects & merging two sites into one

            We have a client that has two sites that rank well for different searches in their market. The main pages ranking are things like advice articles and news pieces. For various reasons, they just want one site. I believe they need to duplicate the content from the outgoing site and place it on the main site, with a 301 redirect from each old page to each new one. What happens when they eventually want to redirect the entire domain? Would these smaller, internal redirects become obsolete, therefore removing any link value they once had? I am not sure how this works or if there is a best practice way to do this. Thanks Gareth

            Technical SEO | | Gmorgan
            0
          • Ant-808

            How long will Google take to stop crawling an old URL once it has been 301 redirected

            I need to do a clean-up old urls that have been redirected in sitemap and was wondering about this.

            Technical SEO | | Ant-808
            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
          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

          Access all your tools in one place. Whether you're tracking progress or analyzing data, everything you need is at your fingertips.

          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.