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 syntax for htaccess

    301 redirect syntax for htaccess

    Technical SEO Issues
    3 3 6.0k
    • 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.
    • 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
      • 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
        • 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
          • 1 / 1
          • First post
            Last post
          • 301 Redirects Showing As 307 Redirects
            0
            1
            64

          • Redirect a 301 Redirect
            RedCaffeine
            RedCaffeine
            0
            5
            98

          • 301 redirect .htaccess
            Christy-Correll
            Christy-Correll
            0
            5
            234

          • Htaccess code to 301 redirect a folder change
            Paul_MC
            Paul_MC
            0
            4
            160

          • To 301 redirect or not to 301 redirect? duplicate content problem www.domain.com and www.domain.com/en/
            Chris-CA
            Chris-CA
            0
            5
            456

          • Need Help writing 301 redirects in .htaccess file
            Dr-Pete
            Dr-Pete
            0
            5
            1.3k

          • Delete 301 redirected pages from server after redirect is in place?
            RuthBurrReedy
            RuthBurrReedy
            0
            5
            4.0k

          • Redirect or not to redirect
            AlanMosley
            AlanMosley
            0
            7
            458

          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