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. Help needed please with 301 redirects in htaccess file.

    Help needed please with 301 redirects in htaccess file.

    Technical SEO Issues
    9 3 2.3k
    • 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.
    • petersommertravels
      petersommertravels last edited by

      In summary, we're currently having issues with our htaccess file. 301 redirects are going through to the new described URL but in addition the new URL is followed by a ? and the old URL. How can we get rid of the ? and previous URL so they don't appear as an ending.

      None of the examples we've found re this issue online appear to work. Can anyone please offer some advice? Can we use a RewriteRule to stop this happening?

      Here's a summary of the htaccess file

      REDIRECT CODE BEGINS HERE

      LONG LIST OF REDIRECTS, which appear to be set up perfectly fine.

      REDIRECT CODE ENDS

      DirectoryIndex index.php

      <ifmodule mod_rewrite.c="">RewriteEngine On

      Options +FollowSymLinks
              DirectoryIndex index.php
              RewriteEngine On
              RewriteCond $1 !^(images|system|themes|pdf|favicon.ico|robots.txt|index.php) [NC]
              RewriteRule ^.htaccess$ - [F]
              RewriteRule ^favicon.ico - [L]
              RewriteCond %{REQUEST_FILENAME} !-f
              RewriteCond %{REQUEST_FILENAME} !-d
              RewriteRule ^(.*)$ /index.php?/$1 [L]</ifmodule>

      DirectoryIndex index.php

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

        Are you putting the code in the .htaccess of the root directory of of the gallery directory? If you're putting it in the root, that is your first mistake. Try putting the following code in the .htaccess of the gallery directory:

        RewriteEngine On
        RewriteBase /

        RedirectMatch 301 (.*)kaunos-tombs-dalyan-photo.html$ http://www.petersommer.com/gallery/

        Replace the .html with .php or whatever the extension of the kaunos-tombs-dalyan-photo file is.

        One question, though. Is kaunos-tombs-dalyan-photo a directory or a file? meaning is your URL technically this: http://www.petersommer.com/gallery/?/gallery/kaunos-tombs-dalyan-photo.html or this: http://www.petersommer.com/gallery/?/gallery/kaunos-tombs-dalyan-photo/index.html

        petersommertravels 1 Reply Last reply Reply Quote 0
        • petersommertravels
          petersommertravels @UnderRugSwept last edited by

          Thanks so much for the quick response Marisa. Apologies if I've confused in any way.

          The 301 redirect of the gallery tombs is just one of a long list of redirects, hence 'other redirects...' I removed the rest just for ease.

          The htaccess is in the main root. I just happened to leave a gallery page as an example of a redirect.

          I wondered if there might be a Rewriterule that I could include in the file to solve this issue across the board rather than deal individually - there's about 100 redirects including the one mentioned.

          If you can assist further that would be brilliant! I'd really appreciate it.

          best wishes,

          Peter

          UnderRugSwept petersommertravels 2 Replies Last reply Reply Quote 0
          • UnderRugSwept
            UnderRugSwept @petersommertravels last edited by

            I'm not sure if I can help further or not, since I'm certainly not an Apache coding expert. Right off the bat it seems like you may have a dynamic URL redirect already in place, so when you add anther redirect, it's in a sense, putting a double redirect on the URLs.

            I wish I could help further, but one thing I will say is that the only way I've found redirects from multiple directories to work is to put the redirects in each corresponding directory's .htaccess file, and not the root. I wish there was an easier way to do it, and if there is, I hope someone will chime in here and enlighten us.

            Sorry I couldn't be of further assistance.

            1 Reply Last reply Reply Quote 0
            • petersommertravels
              petersommertravels @petersommertravels last edited by

              Thanks for trying Marisa. Appreciate your time and effort. Best wishes, Peter

              1 Reply Last reply Reply Quote 0
              • Cyrus-Shepard
                Cyrus-Shepard last edited by

                Hi Peter,

                Would love to help out, but by this point in the thread I'm thoughtfully confused! Any chance we could start from the beginning? If you would like, please list

                • exactly an example URL you are trying to redirect,
                • The exact code that isn't working
                • The end result of how it redirects.

                Not promising I can help any more than Marisa, and maybe my brain just hurts right now, but I'm willing to give it a shot.  Thanks.

                petersommertravels 1 Reply Last reply Reply Quote 0
                • petersommertravels
                  petersommertravels @Cyrus-Shepard last edited by

                  Many thanks Cyrus. Sorry to hear you're confused! Thank you for offering to help.

                  There are redirects of a number of old pages. Here's a sample of them.

                  redirect 301 /index.html http://www.petersommer.com/

                  redirect 301 /writing_index.html http://www.petersommer.com/travel-writing/

                  Unfortunately I'm not sure what isn't working or what needs to be done to fix it. I wish I did! I assume it must be something in the Rewrite Rules or we need to add in some Rewrite Rules to fix it.

                  All the redirects are unfortunately adding a ? and the old URL to the end of the new redirected URL.

                  All are following the same pattern - unfortunately.

                  If you can see any glitches in the Rewrite Rules or can identify something we need to add that will be super.

                  Thanks again, Peter

                  Cyrus-Shepard petersommertravels 2 Replies Last reply Reply Quote 0
                  • Cyrus-Shepard
                    Cyrus-Shepard @petersommertravels last edited by

                    Ha! I always get myself into trouble when trying to answer these .htaccess questions. Someday I'll learn. 🙂

                    I'm not an expert, but here's one thing you can try. Make sure to backup your file before you attempt these, in case you break something you want to be able to quickly back it up. My suspicion is there are conflicting rules in the file that are causing the wrong redirection.

                    -Try changing your rewrite rules to the following format. The "L" indicates this is the last directive, and place no more rewriting rules on this condition.

                    RewriteRule ^tours2006.html http://www.petersommer.com/escorted-archaeological-tours/ [L,R=301]

                    If this doesn't work, let me know and I'll try to find someone who knows more.

                    1 Reply Last reply Reply Quote 2
                    • petersommertravels
                      petersommertravels @petersommertravels last edited by

                      Hi Cyrus,

                      Thank you so very much. Success! I can't tell you how delighted and grateful I am. I have spent hours over the Easter weekend trying to fix it, but to no avail. You are a god in my eyes! You have made my day and halted the rash of broken/duped links emanating from our website.

                      Thank you, thank you, thank you.

                      Very best,

                      Peter

                      1 Reply Last reply Reply Quote 0
                      • 1 / 1
                      • First post
                        Last post
                      • I need help with redirecting chain to another page and 301, I don't understand on how to fix
                        salem4e
                        salem4e
                        0
                        3
                        111

                      • Htaccess file help
                        DirkC
                        DirkC
                        0
                        4
                        120

                      • .htaccess Redirect 301 issues
                        Cyberace
                        Cyberace
                        0
                        5
                        140

                      • Help creating a 301 redirect in my htaccess file
                        Felip3
                        Felip3
                        0
                        4
                        108

                      • Redirect a 301 Redirect
                        RedCaffeine
                        RedCaffeine
                        0
                        5
                        98

                      • 301 Redirect Help
                        dhidalgo1
                        dhidalgo1
                        1
                        3
                        115

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

                      • Do I need a 301 redirect on htaccess if Apache is already configured to serve?
                        riplash
                        riplash
                        0
                        6
                        355

                      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