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
-
Help Setting Up 301 Redirects from Coldfusion Site to Wordpress Site.
I have created a new website and need to redirect all of the previous pages to the new one. The old website was built in coldfusion and the new site is built in wordpress. One of the pages I'm trying to redirect is www.norriseal.com/products.cfm to http://norrisealwellmark.com/products/. This is what I have in my .htaccess file <ifmodule mod_rewrite.c="">Options +FollowSymlinks
Technical SEO | | MarketHubb
RewriteEngine On
RewriteBase /
Redirect 301 /products.cfm http://norrisealwellmark.com/products/</ifmodule> The result of this redirect is http://norrisealwellmark.com/products.cfm How do I prevent the .cfm from appending to the destination URL?1 -
Is there anyway to automatically find complete urls for 301 redirects?
Hello all, I'm working on a large site that is being prepared for a migration. After scraping on screaming frog, WMT, and deepcrawl, and deduping I have a list of 404 pages that need redirected. Many of these URLs are just incomplete URLs. For example the incomplete URL would be: "https://moz.com/beginners-guide-to" when it should be "https://moz.com/beginners-guide-to-seo" I have been finding the correct page manually searching google. With hundreds more to go, I am looking for a way the would be a little less laborious. Thanks! https://moz.com/beginners-guide-to-seo
Technical SEO | | AdamBohr0 -
Should I Parent/Child my Website Pages (need help with terminology too)
Hello I have a website that I am trying to SEO optimise.
Technical SEO | | NikitaG
The current structure of the site is that all pages are linked directly after the domain:
example: www.domain.com**/page01** www.domain.com**/page02** The website is however logically organised in the following form:
www.domain.com**/page01/page02** Sometimes the parenting goes to 3 levels: (please help me with the right term here) Domain
↳ Page001
↳ Page002
↳Page003 My question is: should keep the current structure, or is it worth the effort to re-link the website in a parented way. Are there any benefites to one or the other, and could you point to some video tutorials or documentation to read. BqoDAsx.jpg DMMIC5o.jpg0 -
Increase 404 errors or 301 redirects?
Hi all, I'm working on an e-commerce site that sells products that may only be available for a certain period of time. Eg. A product may only be selling for 1 year and then be permanently out of stock. When a product goes out of stock, the page is removed from the site regardless of any links it may have gotten over time. I am trying to figure out the best way to handle these permanently out of stock pages. At the moment, the site is set up to return a 404 page for each of these products. There are currently 600 (and increasing) instances of this appearing on Google Webmasters. I have read that too many 404 errors may have a negative impact on your site, and so thought I might 301 redirect these URLs to a more appropriate page. However I've also read that too many 301 redirects may have a negative impact on your site. I foresee this to be an issue several years down the road when the site has thousands of expired products which will result in thousands of 404 errors or 301 redirects depending on which route I take. Which would be the better route? Is there a better solution?
Technical SEO | | Oxfordcomma0 -
301 Redirect
Hello, On the 26.2.13 we changed domain names having followed the guidance of both Matt Cutts Youtube videos and googles own online documentation. We have a 301 redirect in place from our old domain ukmotorhomehirerental.com to our new site leisurerentalsdirect.com on a page to page basis. The site structure has not been altered in anyway. Google has been informed of the change of address. After the change the new domain transition was pretty seamless and ranked in the same postion in the SERPsThe one thing I've not done yet is tell all the webmasters who link to the old site that the address has changed (could this be it?)
Technical SEO | | Badapplemedia0 -
Do I need Redirects?
I've recently changed my old static website to a WordPress one. I'd like to know what do do (if anything) about my old links. For example a page on my old site was: www.iainmoran.com/corporate-magician.html - now I'm using WordPress, the url is:
Technical SEO | | iainmoran
www.iainmoran.com/corporate-magician/ My question is, do I need to set up redirects on these old pages (which no longer exist or will Google eventually re-crawl my site and update the links themselves? I'm using the Yoast SEO Plugin for WP and it creates a sitemap, which of course will have my new pages on. But don't want Google to penalise me for having broken links, etc. Many thanks, Iain.0 -
301 redirect or maual edit of new urls
Hello forum! I will get right to the point,I have a 4 year old PR4 site with lots of links (vacation rentals marketplace, like Homeaway), In about a month from now new CMS will be ready and I will be doing redesign of the site. The problem that I have is (as many of you can guess) losing all the old links that rank high = losing traffic / revenue. Two posiblle solutions here: 1. 301 redirect for each page that ranks high - point it to new url 2. Manually editing new urls created by new CMS and making them to be the same as old ones. This means that some number of urls (the ones that rank high and generate traffic) would be exactly the same while other ones would be generated by CMS thus dufferent in many ways (unicode,different keywords etc.) What would You do here? I am more for 301 redirect but I read all kinds of horror stories in drop of SERP. Thank You for help and advices in advance.
Technical SEO | | Gregos0 -
Canonical tag, CNAME and 301 redirect
I have a website with a couple of domains pointing to one IP address. Let's say I have two domains www.example.com and www.example.ca I also see during my SEO analysis that the example.com and the www.example.com (same for the example.ca and the www.example.ca) are triggering server responses. How do I deal with this issue for best SEO. Canonical links? CNAME, or 301 redirects? thanks
Technical SEO | | casper4340