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
-
How to Choose destination page for a 301 redirect?
I am doing some SEO for a wedding chapel in Vegas. There are some old packages that no longer exist and the bounce rate for the page is high so I am planning to 301 the page. How to best determine the best 301 destination? I have a few options. As an example the page was optimized for garden weddings. The page itself does not place well in the SERPS for garden weddings in Las Vegas, but our outdoor wedding packages in Las Vegas page places in the top 10. So that page is in an option. However, there is a different location that has a garden setting. Is that a better choice? Some content might match better than others, but any page I choose would be relevant content. Thank you so much 🙂
Technical SEO | | leslieevarts0 -
Google Deindexing Site, but Reindexing 301 Redirected Version
A bit of a strange one, a client's .com site has recently been losing rankings on a daily basis, but traffic has barely budged. After some investigation, I found that the .co.uk domain (which has been 301 redirected for some years) has recently been indexed by Google. According to Ahrefs the .co.uk domain started gaining some rankings in early September, which has increased daily. All of these rankings are effectively being stolen from the .com site (but due to the 301 redirect, the site loses no traffic), so as one keyword disappears from the .com's ranking, it reappears on the .co.uk's ranking report. Even searching for the brand name now brings up the .co.uk version of the domain whereas less than a week ago the brand name brought up the .com domain. The redirects are all working fine. There's no instance of any URLs on the site or in the sitemaps leading to the .co.uk domain. The .co.uk domain does not have any backlinks except for a single results page on ask.com. The site hasn't recently had any design or development done, the last changes being made in June. Has anyone encountered this before? I'm not entirely sure how or why Google would start indexing 301'd URLs after several years of not indexing these.
Technical SEO | | lyuda550 -
301 redirect of one site version to new domain
Hello all. I today have domain.com that has 10 language versions and the structure is by folders: domain.com/ru/
Technical SEO | | Gregos
domain.com/pl/ etc. Soon I plan redesign,new CMS and I plan to register 9 new ccTLDs. My question is: Can I 301 redirect domain.com/ru/ to domain.ru without having some bad effect on domain.com? I mean,the main domain,com is not going to be affected by permanent redirect of one url to completly new domain right?0 -
Does 301 redirect cause penalty
Good Morning, I am considering doing a 301 (permanent) re-direct of roughly 100 domains, split between my 3 main e-commerce sites. Would taking an action like this put any of the 100 domains or any of the 3 recipient domains at risk of violating G's guidelines? Thanks...
Technical SEO | | Prime851 -
301 Redirect From Dynamic Page To Static
I want to 301 redirect all "id" and "type" numbers from my page dynamic.php page (I have thousands of IDs and thousands of Types) all to a single URL. So for example the following.... www.mysite.com/dynamic.php?id=1&type=5 www.mysite.com/dynamic.php?id=2&type=5 www.mysite.com/dynamic.php?id=3&type=5 www.mysite.com/dynamic.php?id=1&type=6 www.mysite.com/dynamic.php?id=2&type=6 www.mysite.com/dynamic.php?id=3&type=6 ...would all be sent to: www.mysite.com/page.html How can this be done without doing a redirect for each ID/Type?
Technical SEO | | TheDude1 -
301 Redirection of entire section to the homepage
Hi Guys, So here's the deal. Let's say I have a site at mysite.com/ which talks about tomatoes, and I also have a subsection that talks about potatoes at mysite.com/potatoes I want to stop providing information about potatoes altogether so i'm thinking about doing a 301 redirection from all of the pages at mysite.com/potatoes(.*) to the home page. The thing is, mysite.com/potatoes actually has a great page authority (3475 links from 145 domains) so I really don't wan to lose all that juice... Here are my questions: Will the links be added to the ones i have for the homepage already? Since my home page and my /potatoes section ranked for 2 different subjects, how is this transfer going to affect my rankings for the homepage? will it now also rank for both tomatoes AND potatoes? How much time does it usually take for google to recognize the 301 and pass the link juice? Any other tips on optimizing this process? Thank you for your time! -francois
Technical SEO | | nyakim0 -
Redirects on Window Servers - .htaccess equivalent for IIS
I am going to start searching myself, but I have a client on a Windows server needing to do redirects. So besides my usual 'Get a UNIX box', I need to know how to do redirects on IIS. Full site redirect: RewriteCond %{HTTP_HOST} ^[site].com [NC] RewriteRule (.*) http://www.[site]/$1 [L,R=301] as well as page level redirects redirect 301 /[old-page.php] http://www.[site].com/[new-page] And that leads me to the question of RewiteRules also? RewriteRule ^[requested-page].html [server-fed-page].php [L] Thanks if anyone can [redirect] me to a good URL for these. 🙂 Richard
Technical SEO | | Getz.pro0 -
301 redirect: Old pages to new
Hi, We have recently made some changes to our agency site. Looking in webmaster tools we have identified a number of old pages with existing link juice. Not a great deal mostly 32/100 PA. There are a mixture of URLs "meet the team" and people pages etc. The anchor text on the majority of pages is our brand name. Could we now 301 all these pages to one page, or is this a no no in the eyes of Google? Any help greatly appreciated. Best Regards Sean
Technical SEO | | Yozzer0