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. Intermediate & Advanced SEO
    4. 301 Redirect htaccess

    301 Redirect htaccess

    Intermediate & Advanced SEO
    8 3 256
    • 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.
    • UrbanMark
      UrbanMark last edited by

      Hi Guys,

      I have a website that has plenty of links with parameters. For example:
      http://www.domainname.co.uk/index.php?app=ecom&ns=catshow&ref=Brandname-Golf-Shorts&sid=201v04gxs2hlozv161tfo43qk98583el

      I want to place a wildcard redirect on the .htaccess but don't know what exactly code for this. Ideally I want the URLs above to be:

      http://www.domainname.co.uk/Category/Brandname-Golf-Shorts

      Any help pls.

      Thanks,
      Brucz

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

        Hey Mark,

        Finally a question that I can answer (yay!)

        I use the following code on my website:

        <ifmodule mod_rewrite.c="">RewriteEngine On
          RewriteRule ^(.*)$ http://www.it-engelhardt.de/$1 [R=301]</ifmodule>

        It basically takes every URL like http://itengelhardt.de/microconf-2013-hub-page/

        and just redirects it (301 of course!) to http://www.it-engelhardt.de/microconf-2013-hub-page/

        UPDATE 1:  (after carefully re-reading the question)

        OK, hopefully this is the correct answer to your question:

        **Assumptions I made: **

        • You want to extract the category name from the query string (i.e. everything after the '?')
        • "ns=catshow" in the query string stands for "category show" and tells the server to show a category

        Then this is hopefully what you want:

        RewriteCond %{QUERY_STRING} ns=catshow
        RewriteCond %{QUERY_STRING} ref=([^&]+)
        RewriteRule ^index.php /Category/%1? [R=301]

        **What it does: **

        1. checks if "ns=catshow" is present in the query string
        2. extracts the value from the "ref=" variable in the query string and stores it in %1
        3. rewrites every request to the server, that matches conditions 1. and 2. and starts with "index.php" to /Category/%1

        4. the "?" at the end of "/Category/%1?" tells the server to throw away the original query string - this might not be desirable, if not: remove the '?'
        5. the [R=301] tells the server to redirect using HTTP 301

        Tested with: http://htaccess.madewithlove.be/

        UrbanMark 1 Reply Last reply Reply Quote 0
        • UrbanMark
          UrbanMark @cengelhardt last edited by

          Hey Christoph,

          Glad our needs can spring you into action 🙂

          Appreciate that very much, will test it out in the morning and post my findings.

          Thanks again, thats great.

          Mark

          cengelhardt 1 Reply Last reply Reply Quote 1
          • cengelhardt
            cengelhardt @UrbanMark last edited by

            Hey Mark,

            I should not answer questions in around 6 a.m. Sorry for that 😞

            My example works only when you want to redirect from an old domain  to a new one - or from http://www.domain.com to http://domain.com

            If you want the links to be on the same domain, things get tricky quite fast. I'll deep dive into the documentation and be right back

            UrbanMark 1 Reply Last reply Reply Quote 1
            • UrbanMark
              UrbanMark @cengelhardt last edited by

              Hey Christoph,

              No worries, yes anything pre 8am is a risk (coffee depending)!

              Look forward to your next deep post 8am comment 🙂

              Cheers

              Mark

              cengelhardt 2 Replies Last reply Reply Quote 0
              • cengelhardt
                cengelhardt @UrbanMark last edited by

                Hey Mark,

                it is only 07:21 right now, but I updated my original answer.

                Hope you still accept my premature answer 🙂

                Christoph

                1 Reply Last reply Reply Quote 0
                • cengelhardt
                  cengelhardt @UrbanMark last edited by

                  Hey Mark,

                  did this work for you? 
                  Would be happy to hear back.

                  In the meantime enjoy your weekend

                  Christoph

                  1 Reply Last reply Reply Quote 0
                  • Christy-Correll
                    Christy-Correll last edited by

                    Hi Mark, has your question been answered?

                    1 Reply Last reply Reply Quote 0
                    • 1 / 1
                    • First post
                      Last post
                    • How to redirect an url in .htaccess when "redirect 301" doesnt work
                      WilliamKammer
                      WilliamKammer
                      0
                      5
                      173

                    • Can an incorrect 301 redirect or .htaccess code cause 500 errors?
                      ThompsonPaul
                      ThompsonPaul
                      0
                      10
                      2.8k

                    • .htaccess 301 Redirect Help! Specific Redirects and Blanket Rule
                      LynnPatchett
                      LynnPatchett
                      0
                      3
                      3.1k

                    • Mass 301 redirect from a sub-domain - using Joomla or htaccess
                      JohnW-UK
                      JohnW-UK
                      0
                      3
                      674

                    • 301 redirect subdomain to path and 301 for popular pages
                      Mike.Goracke
                      Mike.Goracke
                      0
                      2
                      187

                    • How to conduct catch 301 redirects & have the separate 301 redirects for the key pages
                      BenRWoodard
                      BenRWoodard
                      0
                      2
                      288

                    • Redirects 301
                      PedroM
                      PedroM
                      0
                      3
                      339

                    • Multiple 301 redirects considered a redirection chain?
                      jmueller
                      jmueller
                      1
                      16
                      5.0k

                    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