.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
-
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 -
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 rewrite rule (very specific)
Hello, Awhile back my company changed from http: to https: sitewide (before i started working here). We use a very standard rewrite rule that looks like this: RewriteEngine On
Intermediate & Advanced SEO | | Waismann
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://opiates.com/$1 [R,L] However, with this rule in place, some http: urls are being redirected with a 302 status code. My question is, can I safely change the above code to look like this: RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://opiates.com/$1 [R=301,L] to ensure that every redirected is returned with a 301 status code. The only change is in the [R,L] section. Thanks to whomever can help with this. I'm pretty sure its safe but I dont want the site to go down, even for a second, so figured I would ask first.0 -
How to redirect an url in .htaccess when "redirect 301" doesnt work
I have an odd page url, generated by a link from an external website, it has: %5Cu0026size=27.4KB%5Cu0026p=dell%20printers%20uk%5Cu0026oid=333302b6be58eaa914fbc7de45b23926%5Cu0026ni=21%5Cu0026no=24%5Cu0026tab=organic%5Cu0026sigi=11p3eqh65%5Cu0026tt=Dell%205210n%20A4%20Mono%20Laser%20Printer%20from%20Printer%20Experts%5Cu0026u=fb ,after a .jpg image url, and I can't get it redirect using the redirect 301 in .htaccess to the properly image url as I use to do with the rest of not found urls eg: /15985.jpg%5Cu0026size=27.4KB%5Cu0026p=dell%20printers%20uk%5Cu0026oid=333302b6be58eaa914fbc7de45b23926%5Cu0026ni=21%5Cu0026no=24%5Cu0026tab=organic%5Cu0026sigi=11p3eqh65%5Cu0026tt=Dell%205210n%20A4%20Mono%20Laser%20Printer%20from%20Printer%20Experts%5Cu0026u=fb to just: /15985.jpg
Intermediate & Advanced SEO | | Status0 -
Can an incorrect 301 redirect or .htaccess code cause 500 errors?
Google Webmaster Tools is showing the following message: _Googlebot couldn't access the contents of this URL because the server had an internal error when trying to process the request. These errors tend to be with the server itself, not with the request. _ Before I contact the person who manages the server and hosting (essentially asking if the error is on his end) is there a chance I could have created an issue with an incorrect 301 redirect or other code added to .htaccess incorrectly? Here is the 301 redirect code I am using in .htaccess: RewriteEngine On RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/.]+/)*(index.html|default.asp)\ HTTP/ RewriteRule ^(([^/.]+/)*)(index|default) http://www.example.com/$1 [R=301,L] RewriteCond %{HTTP_HOST} !^(www.example.com)?$ [NC] RewriteRule (.*) http://www.example.com/$1 [R=301,L] Could adding the following code after that in the .htaccess potentially cause any issues? BEGIN EXPIRES <ifmodule mod_expires.c="">ExpiresActive On
Intermediate & Advanced SEO | | kimmiedawn
ExpiresDefault "access plus 10 days"
ExpiresByType text/css "access plus 1 week"
ExpiresByType text/plain "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType application/x-icon "access plus 1 year"</ifmodule> END EXPIRES (Edit) I'd like to add that there is a Wordpress blog on the site too at www.example.com/blog with the following code in it's .htaccess: BEGIN WordPress <ifmodule mod_rewrite.c="">RewriteEngine On
RewriteBase /blog/
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]</ifmodule> END WordPress Thanks0 -
A newbie to this..what is a good way to find local directories for your city or general directories that should be submitted to
A newbie to this forum...hope have put the question the right way What is a good way/source to find which directories are suitable for a business. How to identify directories which are more localised..
Intermediate & Advanced SEO | | grovermohit0 -
301 Redirect htaccess
Hi Guys, I have a website that has plenty of links with parameters. For example:
Intermediate & Advanced SEO | | UrbanMark
http://www.domainname.co.uk/index.php?app=ecom&ns=catshow&ref=Brandname-Golf-Shorts&sid=201v04gxs2hlozv161tfo43qk98583el I want to place a wildcard redirect on the .htaccess but don't know what exactly code for this. Ideally I want the URLs above to be: http://www.domainname.co.uk/Category/Brandname-Golf-Shorts Any help pls. Thanks,
Brucz0 -
.htaccess code ?
What is the code to redirect www.xyz.com/abc where abc is a folder to www.xyz.com/abc.html
Intermediate & Advanced SEO | | seoug_20050