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 rewrites

    Htaccess rewrites

    Technical SEO Issues
    7 3 705
    • 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

      We’re using wordpress, and we have the following in the .htaccess:

      BEGIN WordPress

      RewriteEngine On

      RewriteBase /

      RewriteRule ^index.php$ - [L]

      RewriteCond %{REQUEST_FILENAME} !-f

      RewriteCond %{REQUEST_FILENAME} !-d

      RewriteRule . /index.php [L]

      END WordPress

      We have a URL like http://subdomain.example.com/select-a-card/?q=fuel, and I want to rewrite it so that it becomes http://subdomain.example.com/fuel-card/

      What do I need to add to the htaccess to do this??

      Thanks,

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

        Try this:

        BEGIN WordPress

        <ifmodule mod_rewrite.c="">RewriteEngine On
          RewriteBase /
          
          # Custom Rewrite Rules
          RewriteCond %{REQUEST_URI} ^/select-a-card/$ [NC] RewriteCond %{QUERY_STRING} ^q=fuel$   RewriteRule ^index.php$ /fuel-card/? [R=301,NC,L]
          
          RewriteRule ^index.php$ - [L]
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteRule . /index.php [L]</ifmodule>

        END WordPress

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

          Hi Ben,

          Thanks for replying. Unfortunately I've tried the above and it's not working.

          I've tried escaping everything, but still no joy. Could this be clashing with wordpress permalink redirects perhaps?

          blacey Qon 2 Replies Last reply Reply Quote 0
          • blacey
            blacey @AndrewAkesson last edited by

            No it wont be conflicting with WordPress, just a matter of getting the syntax correct. I'll try and amend my initial solution later this evening and report back, thanks in advance for your patience.

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

              Ok, so how about if I make the ask a bit easier...

              Whilst not an ideal solution, it would be good if I could just rewrite

              http://subdomain.example.com/select-a-card/?q=fuel

              to

              http://subdomain.example.com/select-a-card/fuel/

              ...or ideally with a trailing slash too: http://subdomain.example.com/select-a-card/fuel/

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

                This should work:

                RewriteRule ^([^/]*)/$ /select-a-card/?q=$1 [L]

                This will redirect _http://subdomain.example.com/select-a-card/?q=__**anyname**_ to _http://subdomain.example.com/**anyname**__/_. If you just want to 301 the one page, try this:

                Redirect 301 /select-a-card/?q=fuel http://subdomain.example.com/fuel-card/

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

                  I managed to strip out the '?q=' query with the htaccess below, but unfortunately this breaks the query. Any way around this?? (http://subdomain.example.com/select-a-card/?q=fuel)

                  RewriteEngine On
                  RewriteBase /
                  RewriteCond %{REQUEST_URI} ^/$
                  RewriteCond %{QUERY_STRING} ^q=fuel$
                  RewriteRule ^(.*)$ /fuel/? [R=301, L]

                  BEGIN WordPress

                  RewriteCond %{REQUEST_FILENAME} !-f
                  RewriteCond %{REQUEST_FILENAME} !-d
                  RewriteRule . /index.php [L]

                  END WordPress

                  1 Reply Last reply Reply Quote 0
                  • 1 / 1
                  • First post
                    Last post
                  • Htaccess noob
                    Keszi
                    Keszi
                    0
                    4
                    96

                  • .htaccess Question
                    seanginnaw
                    seanginnaw
                    0
                    2
                    63

                  • .htaccess code
                    KevinBudzynski
                    KevinBudzynski
                    0
                    8
                    68

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

                  • .htaccess redirects
                    ThompsonPaul
                    ThompsonPaul
                    0
                    15
                    285

                  • Htaccess query
                    ShaMenz
                    ShaMenz
                    0
                    6
                    469

                  • Mod Rewrite / .htaccess avoid duplicate content
                    blacey
                    blacey
                    0
                    8
                    4.0k

                  • URL Rewrite
                    oznappies
                    oznappies
                    0
                    4
                    1.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