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
-
Htaccess file help
Hi, thanks for looking i am trying (and failing) to write a htaccess for the following scenario <colgroup><col width="679"></colgroup> http://www.gardening-services-edinburgh.com/index.html http://www.gardening-services-edinburgh.com http://www.gardening-services-edinburgh.com/ | so that all of these destinations goto the one resource any ideas? thanks andy
Technical SEO | | McSEO0 -
Switching forum software - 301 redirects?
Hi everyone I'm working on a successful Wordpress site that also has a forum attached. The forum currently uses YAF forum software, which requires Windows hosting. The site owner wants to switch to Linux hosting. This is not a problem for WP, but it does mean that we'll need to transfer the forum to Xenforo or something similar that runs on Linux. We're OK with the technical side of this, but we're worried about the SEO implications. The URL for every forum post (more than 50,000 of them) is going to change during this transfer. It seems completely impractical to 301 each of those, so should I just 301 the URLs that have inbound links? Also, what is google's algo going to think when we suddenly have ~50,000 404s? Many thanks in advance! J
Technical SEO | | van280 -
Need help with home page on site
Hello! Thanks for reading in advance! I've got a relatively old site (12 year old domain) that has experienced a drop in rankings specifically for our home page. Some of the key terms that I'd assume we would rank well for are: "expedite us passport" According to SEOMOZ, our on page optimization receives a C for the termr. also, the root domain and page have decent links, etc. However; looking at Google (logged out and in incognito mode in chrome), a page on our site http://www.passportsandvisas.com/passport/index.asp ranks well and our HOME page isn't listed in the top 50 or 100. THis is the case for a lot of keywords we used to rank well for. I would have thought our home page would have at least outranked an internal page. Any thoughts would be very, very helpful!
Technical SEO | | santiago230 -
Can you do a 301 redirect without a hosting account?
Trying to retire domain1 and 301 it to domain2 - just don't want to get stuck having to pay the old hosting provider simply to serve a .htaccess file with the redirect rule.
Technical SEO | | TitanDigital0 -
To 301 redirect or not to 301 redirect? duplicate content problem www.domain.com and www.domain.com/en/
Hello, If your website is getting flagged for duplicate content from your main domain www.domain.com and your multilingual english domain www.domain.com/en/ is it wise to 301 redirect the english multilingual website to the main site? Please advise. We've recently installed the joomish component to one of our joomla websites in an effort to streamline a spanish translation of the website. The translation was a success and the new spanish webpages were indexed but unfortunately one of the web developers enabled the english part of the component and some english webpages were also indexed under the multilingual english domain www.domain.com/en/ and that flagged us for duplicate content. I added a 301 redirect to redirect all visitors from the www.domain/en/ webpages to the main www.domain.com/ webpages. But is that the proper way of handling this problem? Please advise.
Technical SEO | | Chris-CA0 -
Index.php and 301 redirect with Joomla
Hi, I'm running Joomla 1.7 with SEF on and I'm trying to do a htaccess redirect which fails. I have approximately 100 in effect so far and all working fine, but I have one snag. Index.php is not working as I need it to when it's redirected to www.myurl.com/ If I turn on index.php redirect to root using this code #index.php to root
Technical SEO | | NaescentAdam
RewriteCond %{HTTP_HOST} ^myurl.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.myurl.com$
RewriteRule ^index.php$ "http://www.myurl.com/" [R=301,L] And then go to www.myurl.com/test.html I'm redirected to the homepage. I think this is because all pages are index.php in joomla. SEOMOZ and Google both think that index.php and root are duplicate pages. Does anyone have any advice for overcoming this? Thanks, Adam0 -
How long should you keep 301 redirects?
Hi, Back in 2009 I decided to update an older site from .htm and .shtml to .php. In order to minimize the impact I would go in every month and do a 301 redirect on the .shtml page to the new .php page. So I have many that range from 2009 through 2010. I had left the old 301's because I felt they would only be used if needed but I would think I should clean up my .htaccess by removing the old 301 redirects if they are not needed. How long should you keep this type of 301 redirect? Thanks!
Technical SEO | | Force70 -
301 Redirect Question
I'm working on a site that has a lot of indexed pages and backlinks to both domain.com and www.domain.com. Will using a 301 redirect to send domain.com to www.domain.com merge all of the indexed pages and links over to www.domain.com, thereby strengthening the www?
Technical SEO | | Yo_Adrian0