Help needed please with 301 redirects in htaccess file.
-
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
-
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
-
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.
-
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
-
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.
-
Thanks for trying Marisa. Appreciate your time and effort. Best wishes, Peter
-
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.
-
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
-
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
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
Browse Questions
Explore more categories
-
Moz Tools
Chat with the community about the Moz tools.
-
SEO Tactics
Discuss the SEO process with fellow marketers
-
Community
Discuss industry events, jobs, and news!
-
Digital Marketing
Chat about tactics outside of SEO
-
Research & Trends
Dive into research and trends in the search industry.
-
Support
Connect on product support and feature requests.
Related Questions
-
301 redirect from dynamic url to static page
Hi, i want to redirect from this old link http://www.g-store.gr/product_info.php?products_id=1735/ to this one https://www.g-store.gr/golf-toualetas.html I have done several attempts but with no result. I anyone can help i will appreciate. My website runs in an Apache server with cpanel. Thank you
Technical SEO | | alstam0 -
Should I resubmit a 301 redirected domain in Webmaster Tools
We recently switched over a .com site to a new server. The .com site had a .co.uk domain redirecting to it previously, but when the switchover happened, the .co.uk was forgotten about. We have now realised what has happened, but not before taking a hit with our rankings. The .co.uk is still indexed in Google and now that we have sorted the redirects they are pointing to the right places. My question now; is there anything further I need to do? I know that the .co.uk will soon be removed from the SERPs, but I just want to make sure I haven't forgotten anything.
Technical SEO | | Ben_Malkin_Develo0 -
Updating inbound links vs. 301 redirecting the page they link to
Hi everyone, I'm preparing myself for a website redesign and finding conflicting information about inbound links and 301 redirects. If I have a URL (we'll say website.com/website) that is linked to by outside sources, should I get those outside sources to update their links when I change the URL to website.com/webpage? Or is it just as effective from a link juice perspective to simply 301 redirect the old page to the new page? Are there any other implications to this choice that I may want to consider? Thanks!
Technical SEO | | Liggins0 -
Need help with rel canonical!
I have a client who's MOZ crawl is coming back with 62 "notices" about rel canonical. Is this bad? On the report, it lists the url, then "Tag Value" as the home page.....what does this mean exactly? Are they pointing all the pages to the home page? I think I have 301 and rel can confused....
Technical SEO | | cschwartzel0 -
Is anyone able to check this 301 redirect for errors please?
Hi, I had a developer write a 301 wildcard for redirecting old hosted site to a new domain. Old URLS looked like /b/2039566/1/akai.html
Technical SEO | | Paul_MC
With varying letters & numbers. I have 26,000 crawl errors in GWT and I can only imagine it's because this is looping?
Can anyone advise if this would be causing grief? Thanks
Paul RewriteCond %{HTTP_HOST} ^vacuumdirect.com.au$ [OR]
RewriteCond %{HTTP_HOST} ^www.vacuumdirect.com.au$
RewriteRule ^/?$ "http://www.vacuumbag.net.au/vacuum-cleaners.html" [R=301,L] <ifmodule mod_rewrite.c="">RewriteEngine On
RewriteBase /
RewriteRule ^p/([0-9]+)/(.*) default/$2 [R=301,L]</ifmodule> <ifmodule mod_rewrite.c="">RewriteEngine On
RewriteBase /
RewriteRule ^c/([0-9]+)/1/(.*) default/vacuum-bags/vacuum-cleaner-bags-$2 [R=301,L]</ifmodule> <ifmodule mod_rewrite.c="">RewriteEngine On
RewriteBase /
RewriteRule ^p/([0-9]+)/(.*) $2 [R=301,L]</ifmodule> <ifmodule mod_rewrite.c="">RewriteEngine On
RewriteBase /
RewriteRule ^c/([0-9]+)/(.*) default/$2 [R=301,L]</ifmodule>0 -
Static site to wordpress - avoiding 301 redirects
Moving our static website to wordpress, pages currently end in the .htm extension and for reasons of me having to do all the moving myself and wanting to preserve link equity is there any way I can run the pages with a .htm extension in Wordpress? Tried using a plug-in by Daddy Design but it seems a bit hit and miss at times. I basically need to keep the url's the same as I will not be able to get the vast majority of my links altered to the new pages, plus I am doing this by myself!
Technical SEO | | Jon-C0 -
301 redirects
Hi, I am a working on a new web site, and I want to redirect all the urls of another site (on a different host) to this one. According to both hosts it is "impossible" to do this for all urls. I don't believe that to be the case, but how do I do this? And, should both sites be hosted on the same server first?
Technical SEO | | vibelingo0 -
What should be use 301 or 302 redirection for 404 pages
Please suggest which redirection we should use for 404 pages- 301 or 302. If you can elaborate it with reason then it will be highly appreciated.
Technical SEO | | koamit0