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

    Htaccess query

    Technical SEO Issues
    6 4 469
    • 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.
    • AndrewAkesson
      AndrewAkesson last edited by

      I'm currently working on a live version of a clients website which has duplication issues. With .htaccess, I need to rewrite URL's of the following format:

      vacancy.php?id=802 to vacancy/?id=802

      I tried adding the following line but it returned a 500, and don't want to keep taking the site out.

      RewriteRule ^vacancy/?id=([0-9]+)$ vacancy.php?id=$1 [R=301, L]

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

        Here's the format you may need to follow, I'm not 100% positive this will work for you but I know this is how 301s are setup:

        redirect 301 vacancy.php?id=802  **yourdomain.com/path-to-location/**vacancy/?id=802

        AndrewAkesson 1 Reply Last reply Reply Quote 0
        • AndrewAkesson
          AndrewAkesson @danbocain last edited by

          Sorry, I should have been more clear. There are hundreds of vacancy ID's which change over time, so I need to use a rewrite rule to handle all cases now and in the future.

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

            Hi,

            please back up your .htaccess before attempting

            Redirect match might work, but only if you are redirecting all to one - Keep in mind the initial directive needs to be changed to your specific scenario, as well as the destination URL

            RedirectMatch 301 ^page.php?id=(.*).htm$ http://www.example.com/content/$1.html

            Or you could do it one by one -

            RewriteCond %{QUERY_STRING} ^id=1$
            RewriteRule ^page.php$ http://www.example.com/content/page? [R=301,L]

            Or here is a link to a resource (I HAVE NOT TESTED OR USED) but gets lots of good feedback, for helping you make easier work out of hundreds of dynamic redirects

            http://www.mbstrategic.com/02/301-redirects-for-dynamic-urls-to-static-pages-with-htaccess/

            Hope this helps

            PS after a seconf look, your initial attempt might work, you just need a condition which would be similar to

            RewriteCond %{QUERY_STRING} ^id=1$

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

              Hi Matt,

              The 500 Error is caused by the "space" in  [R=301, L]

              Should be [R=301,L]

              Hope that helps,

              Sha

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

                Hi again Matt,

                Actually, you don't need to be using the 301 at all. A simple rewrite will do what you are wanting.

                If you do it like this:

                RewriteRule ^vacancy/([0-9]+)$ vacancy.php?id=$1 [L]

                your URLs would be a lot more friendly.

                The resultant URLs would look like this:

                /vacancy/12345

                Hope that helps,

                Sha

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                • Should I canonicalize URLs with no query params even though query params are always automatically appended?
                  LeahH
                  LeahH
                  0
                  3
                  24

                • Schema query
                  Martijn_Scheijbeler
                  Martijn_Scheijbeler
                  0
                  2
                  65

                • Htaccess redirects
                  Tom-Anthony
                  Tom-Anthony
                  0
                  3
                  220

                • Redirection in .htaccess
                  Bharath_ATZ
                  Bharath_ATZ
                  0
                  5
                  91

                • Htaccess Rewrites
                  Klement69
                  Klement69
                  0
                  4
                  316

                • Htaccess file
                  DMGoo
                  DMGoo
                  0
                  5
                  437

                • Htaccess rewrites
                  AndrewAkesson
                  AndrewAkesson
                  0
                  7
                  705

                • Query String Redirection
                  JoeQuery
                  JoeQuery
                  0
                  3
                  1.4k

                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