.htaccess newby
-
Sorry to ask a really dumb question. I want to sort out a load of old 404 errors. I've exported the list of URL and I'm more than happy to go through that and work out what needs to go where.
After that my only option at the moment is to use the re-direct function in my WordPress install and do all the work manually. There are loads to do so I want to be able to upload all the re-directs.
I know I need to create a htaccess file and upload it. I know where to upload it.
This is where I get nervous. I need to get this file right. Is there a really obvious idiots file which I can use and then save as the correct file type? I've got all the URLs in a CSV at the moment.
Sorry for being a bit thick. Hope you can help.
-
Tested and all working!
-
Thanks for that.
All done now, fingers crossed!
Richard
-
Yeah, that looks to be the right file. So, in this case, I'd put the new redirects right after the current redirect.
redirect permanent /index.html http://www.global-lingo.com/index.php
PUT NEW REDIRECTS HERE
BEGIN WordPress
Let me know if that works!
-
Got one.
This is the content - not certain that's what I need?
redirect permanent /index.html http://www.global-lingo.com/index.php
BEGIN WordPress
<ifmodule mod_rewrite.c="">RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]</ifmodule>END WordPress
-
Ah, I see what you are saying. You want to download the one from the site root for redirects. Typically, that is going to be something like a /public_html or /httpdocs folder. Do you have an htaccess file there?
-
That's what I want to do. But I can't be sure I have the right file. There are .htaccess files in a few folders
Thanks for bearing with me Matthew
-
Hey -
Glad you got everything in the right format!
Can you download your current .htaccess file via FTP? I'd download that and then add the new redirects at the bottom of the file and then upload the file. Be sure to save a backup of the htaccess file before you make changes.
Let me know if that works? Thanks,
Matthew -
Ok now I'm stuck again!
I have the list, in the right format, thanks to Matthew.
I can see where to upload the file, but now I'm worried that it will replace all my existing redirects. From the WordPress site I can't see where I can export all the existing redirects so that I could at least add my new ones to the existing ones and upload a new file.
Any ideas guys?
-
Brilliant, thanks Matthew
-
Hey Richard,
You are really close! In column A, do a find for "http://www.global-lingo.com" and replace with nothing. That way you are left with:
A = /news/2009/12/news-internet-translations/
B = http://www.global-lingo.com/blog/
C = redirect 301 /news/2009/12/news-internet-translations/ http://www.global-lingo.com/blog/
Thanks,
Matthew -
Hi Matthew,
Sorry, pretty nervous now!
Here's what I have in the columns
A = http://www.global-lingo.com/news/2009/12/news-internet-translations/
B = http://www.global-lingo.com/blog/
C = redirect 301 http://www.global-lingo.com/news/2009/12/news-internet-translations/ http://www.global-lingo.com/blog/
I think I got a little lost with the full URL in column A. What should I remove? Or have a got it correct? Sorry to use the real URL I just want to make sure I get this correct.
Thanks
Richard
-
Hi Matthew,
That is the perfect answer, thank you so much. Just creating the file was where I was getting stuck and knowing what to put in the columns.
what I have at the moment is:
Column A = 404 url
Column B = URL I want
That solution is perfect, I'm more than happy using that!
-
Hi Richard,
Updating htaccess files can be tricky, especially with that risk of wrecking your site if you do something wrong. So, not a dumb question at all.
WordPress is a great way to add redirects, but if you are dealing with hundreds that can equal a lot of time.
So, if you are looking for a way to quickly build the htaccess file vs. doing everything manually in WordPress, my trick is use to a concatenation function in Excel. That way I can write hundreds of redirects at once and then copy the resulting text into the htaccess file.
The general idea is you have your old URL path in col A, the new URL (full URL) in column B, and then in column C, you'd have a formula that looks something like this (obviously line numbers might change):
="redirect 301 " & A2 & " " & B2
You could then copy column C and add that to your .htaccess file. Of course, back up the htacecss file first. The only word of caution would be to make sure you have valid paths in column A (no special characters, no full URLs, etc.).
Hope that helps.
-
Hi Tom,
Thanks for the quick response. That's why I'm being very careful. I have used the re-direction tool but as there are quite a lot to do I was looking for some way to create one big file and then upload rather than copy and paste nearly 300 entries
-
Hey Richard
This isn't a thick question at all - you're very wise to take care with this. A faulty .htaccess file can cause chaos!
Just wanted to make a suggestion - if you're running WordPress have you tried the Redirection plugin? It does all of the rewriting for you - just pop in the old URL and the new URL and you're on your way. Comes with a few other features too and has had tons of downloads over the years.
If you want to go down the route of self-education, check out the SEOMoz redirection guide and also this blog post on some useful .htaccess snippets.
I'd recommend using the redirection plugin for 2-3 urls, check it works then look at the generated .htaccess file in your website's backend. From there, you can see the correct format and filetype etc. If the tool works, just continue to use it.
Hope this helps!
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
-
Mass 301 redirect in htaccess
I use ScreamingFrog to generate sitemaps for my Magento 2 multistore, but I recently noticed two issues. Each category/page has two URLs. One with / and the end and one without. Every product has two URLs. One with /product-name and the other /shop/product-name. The URLs are canonicalised, but this is still a problem and I'm not sure exactly how to execute this in the htaccess file. So I need to: Remove all URLs without the / at the end and redirect them all to the URL with / at the end. Or vice versa. 301 redirect every single product (there are over 400) from shop/product-name to /product-name. How do I do this en mass in the htaccess file?
Intermediate & Advanced SEO | | moon-boots0 -
Htaccess - Redirecting TAG or Category pages
Hello Fellow Moz's, We have an issue redirecting some /TAG and /Category pages to inner pages. As an example we use: RedirectMatch 301 /category/Sample-Category(.*) https://OurDomain.com.au/New-Page//$1 That works well. The issue is we have other categories and tags that are named similar to /Sample-Category As an example, if we try to redirect /Sample-Category-1 to /New-Page-1 - it will not work, and redirects to /New-Page I assume this is because /Sample-Category is already being redirected, so anything after /Sample-Category like -1 or -2 or -3 etc, will not be recognized. Anyone know of a workaround?
Intermediate & Advanced SEO | | Jes-Extender-Australia0 -
Hacked website - Dealing with 301 redirects and a large .htaccess file
One of my client's websites was recently hacked and I've been dealing with the after effects of it. The website is now clean of malware and I already appealed to Google about the malware issue. The current issue I have is dealing with the 20, 000+ crawl errors which are garbage links that were created from the hacking. How does one go about dealing with all the 301 redirects I need to create for all the 404 crawl errors? I'm already noticing an increased load time on the website due to having a rather large .htaccess file with a couple thousand 301 redirects done already which I fear will result in my client's website performance and SEO performance taking a hit as well.
Intermediate & Advanced SEO | | FPK0 -
6 .htaccess Rewrites: Remove index.html, Remove .html, Force non-www, Force Trailing Slash
i've to give some information about my website Environment 1. i have static webpage in the root. 2. Wordpress installed in sub-dictionary www.domain.com/blog/ 3. I have two .htaccess , one in the root and one in the wordpress
Intermediate & Advanced SEO | | NeatIT
folder. i want to www to non on all URLs Remove index.html from url Remove all .html extension / Re-direct 301 to url
without .html extension Add trailing slash to the static webpages / Re-direct 301 from non-trailing slash Force trailing slash to the Wordpress Webpages / Re-direct 301 from non-trailing slash Some examples domain.tld/index.html >> domain.tld/ domain.tld/file.html >> domain.tld/file/ domain.tld/file.html/ >> domain.tld/file/ domain.tld/wordpress/post-name >> domain.tld/wordpress/post-name/ My code in ROOT htaccess is <ifmodule mod_rewrite.c="">Options +FollowSymLinks -MultiViews RewriteEngine On
RewriteBase / #removing trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ $1 [R=301,L] #www to non
RewriteCond %{HTTP_HOST} ^www.(([a-z0-9_]+.)?domain.com)$ [NC]
RewriteRule .? http://%1%{REQUEST_URI} [R=301,L] #html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]+)$ $1.html [NC,L] #index redirect
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.html\ HTTP/
RewriteRule ^index.html$ http://domain.com/ [R=301,L]
RewriteCond %{THE_REQUEST} .html
RewriteRule ^(.*).html$ /$1 [R=301,L]</ifmodule> The above code do 1. redirect www to non-www
2. Remove trailing slash at the end (if exists)
3. Remove index.html
4. Remove all .html
5. Redirect 301 to filename but doesn't add trailing slash at the end0 -
Htaccess Question - Is this the way to go to consolidate?
Hi all, My site seems to have www.xyz.com, http://www.xyz.com, http://xyz.com and other variations! From an old agency doing this. All showing differing backlinks etc. SO I want to merge them so I can just look at one analytics account - with everything combined. I want it just to consolidate all to https:///www.xym.com as the client wants - how do I do this? Does it take long to take effect?? Also I presume in webmaster I'll have to set up the preferred extension? Thanks very much for any advice 🙂
Intermediate & Advanced SEO | | VMLQais0 -
Best .htaccess guides in your bookmark?
It would be helpful if you can share .htaccess guides you're currently using. Thanks in advance! 🙂
Intermediate & Advanced SEO | | esiow20130 -
.htaccess files
I am working with a clients website which has multiple htaccess files (.htaccess , .htaccess.holiding, and .htaccess.live -all in the same directory) My question is how does a server process these files? All 3 files? Currently the domain has 301 redirect showing for the home page to the mobile site (which is a problem) in one of the files (.htaccess but not others) Has anyone come across this before with regard to SEO problems?
Intermediate & Advanced SEO | | OnlineAssetPartners0 -
Can some brilliant mozzer out there teach a moron/newbie like me how to 301 redirect several URL's I have?
Okay - I am a supermodel. I look pretty. My legs are amazing. My cheekbones are high. But when it comes to 301 redirects I am the ugliest supermodel on the block. Crap, here is the truth: I am not even a supermodel. I am just a middle-aged, goofy looking dude who is a newbie to fixing websites. I have inherited several sites from a friend and I have been helping by creating solid contextual links internally and externally for a while. But, when Roger the wondrous SEOMoz robot talks to me, he says, "oops, it looks like your foolish freak self has a site that has both a www. and a non-www, which can create competition for yourself." What do I do when he says that? I just whisper a "thank-you" but gently press the skip this step button and go on with my life because I do not know how to make my non-www.'s redirect into the www. sites... Now, I have sort of asked this question on the site before, but I was answered by someone who does not understand my level of ignorance. any use of the word canonical or just put this lfwjkshj.htp/php inside the left ear of your mom, does not tell me anything so, is there any willing and kind soul who can walk me through redirecting several of my sites to their proper home - kind of like Carl Chubbs Weathers did for Happy Gilmore in that Academy Award winning classic? Thanks for the help in advance best, dumbhead
Intermediate & Advanced SEO | | creativeguy0