When & Where to use the .htaaccess redirect?

Ive got an issue with one site (soon to be 2) where I have changed the url file name from example : .site.co.uk/prices.html to
.site.co.uk/PAT_testing_prices.html (In my latest adventure of delving into SEO)

Should I be using a .htaaccess redirect in this situation as my old URL`s are still ranked in some instances page 1 of google/yahoo, but when the link is clicked, it throws up a this file could not be found be found on the server,thus loosing a potential viewer/customer…

Will the search engines love me or loathe me for using it ?

And where should this code be uploaded to, meaning in the <head> of the new file or in a completely new html file uploaded to the root folder on the server - If the later what should the html file be called ?

Any help will be greatly appreciated :slight_smile:

p.s Apologies if this is in the wrong forum - please relocate to suit - Thankyou

[Thread moved to Apache forum, as that deals with .htaccess.]

Basically, if the old page no longer exists or has been renamed, you want people to redirected to the new page. So yes, set up a .htaccess file (in the root folder on your server) and redirect the old page to the new.

E.g. for each moved page, have a line like this:

Redirect 301 /folder/old-page.html /newfolder/newpage.html

I’m sure Google is happier with this than to find that a page no longer exists.

Hey Ralph,

I reckon I may have screwed up actually! lol

What I did was log into the server, and changed the name of the html file on the fly.

Now I know google has indexed the new html files as Ive checked :

site:PAT Tester providing PAT Testing in Birmingham Worcester Bromsgrove Redditch Dudley Worcestershire West Midlands

But the old URL`s are still ranking on page 1 of the SERPS, and not the newer html file name - Does this mean Im just going to have to wait for the old files to drop out of the SERPS, eventually being overidden by the new html file name. Because I havnt got an “old” file to place a re-direct in. In hindsite I should have uploaded a brand new html file with the new name, and then placed the .htaaccess file in the old file, thus resulting in a “re-direct”…

Ive just spoke (via typing) to the online help for my web hosting company and they have said to write the following :

redirect 301 faq.html http://www.jmillselectrical.co.uk/pat_testing_faq.html

and then save the file type as a .htaaccess file and just upload it to the root folder

Yes, over time the Google database will be updated. Whether the PR will carry from one page to another, though, I’m not sure.

they have said to write the following :

redirect 301 faq.html http://www.jmillselectrical.co.uk/pat_testing_faq.html

and then save the file type as a .htaaccess file and just upload it to the root folder

Yes, that’s fine. Only problem is that is can be tricky to work with a file starting with a dot on your computer. so you may need to name it something like htaccess.txt, upload, then rename on the server. Or just go straight to the server and create it there with the correct name (though there is often one there anyway). It’s worth checking on the server first, and check if there’s anything in the .htaccess file first. Uploading a new one will overwrite the old one, so you’d lose anything in there already.

Poor Ralph! Anyway, thanks for moving ben to Apache.

ben,

If your redirections are simply to prepend PAT_testing_ to a few .html files, that’s a job that mod_alias is better suited for (the Redirect series of commands). If you need to check whether the old files still exist or not (because you didn’t rename ALL your .html files), then mod_rewrite has the power to do that.

Redirect 301 prices.html [COLOR="Red"]/PAT_testing_prices.html[/COLOR]

is the mod_alias version which is much faster because mod_alias is part of Apache’s core and doesn’t require the regex engine (at least the non-regex versions of mod_alias directives don’t). The redirection in red is REQUIRED to be an absolute redirection (I’ve used the “internal” version with the leading / rather than http://domain/…).

If you need to check whether prices.html still exists before making such a redirection, mod_rewrite is the tool to use:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^prices\\.html$ PAT_testing_prices.html [R=301,L]

Of course, ‘prices’ in this example can easily be extended to capture all (lowercase) filenames by replacing ‘prices’ with ‘([a-z]+)’ in the regex and ‘$1’ in the redirection (all without the single quotes!).

The R=301 flag tells search engines that you’ve moved the page so they will thank you by moving the file in their db, too, which will have the effect of saving your PR. Otherwise, you’re starting afresh on the PR for the “new” page.

WHERE should it be loaded? OMG! That’s what your .htaccess file is for! PLEASE read the tutorial Article linked in my signature for more information (and sample code) about Apache’s mod_rewrite.

Your host gave the same answer (for few files) as above EXCEPT that they used the full (absolute) redirection whereas only the internal (absolute) redirection is necessary. Okay, EITHER if fine but the mod_alias redirection MUST be absolute!

Regards,

DK

Hi David, (and Ralph)

Thanks for the input guys.

David… I can see your a whizz at this stuff, I must point out im not! :slight_smile: I have about as much knowledge in programming as flight time clocked up in space, so excuse me for being, well to put in bluntly “thick” but Im kinda confused.:lol: I have tried to read your explanation on your site, but most of it is going over the top of my head.Im not the brightest of stars or should that be spacedust!

what I will say is Ive created a .htaccess file with the following in, is this suffice to redirect the old URLs to the recently renamed URLs ? :

Redirect 301 prices.html /PAT_testing_prices.html
Redirect 301 legislation.html /PAT_legislation.html
Redirect 301 testimonials.html /PAT_testimonials.html
Redirect 301 faq.html /PAT_faq.html

From the above, am I right in saying that I will loose all Page ranking/results ?

if so should I use the following instead to retain PR :

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^prices\.html$ PAT_testing_prices.html [R=301,L]
RewriteRule ^legislation\.html$ PAT_.html [R=301,L]
RewriteRule ^testimonials\.html$ PAT_testimonials.html [R=301,L]
RewriteRule ^faq\.html$ PAT_faq.html [R=301,L]

If the above is ok, Ill go ahead and upload this straight to the server.

I wont upload anything untill, I have your professional say in the matter.

Regards

Ben

Ive tested the server with the little test files you stated on your site :

test.html
php.test
.htaccess

and it does redirect to the PHP file, so at least I know its enabled and working…

ben,

That’s a good sign … but it only applies to mod_rewrite. Redirect is the simple version (mod_alias) which is part of Apache’s core so it can’t be turned off.

Aw, that’s the same thing as the simple Redirect statements but (not) using the power of mod_rewrite’s regex engine (after delaying to load the engine for EVERY request). In other words, it’s important to know the correct tool and, for four simple redirections like this, Redirect is the correct tool (because it’s fastest).

As for the tutorial, if you have questions, the fastest way to contact me is via e-mail, i.e., the contact form on the website. Do not be afraid to ask as that’s the best way to clear away the cobwebs!

Regards,

DK

Cheers DK,

Just out of interest how quick are search engines able to update after submitting a .htaccess file with a 301 redirect to the server Ive just done :

Redirect 301 prices.html /PAT_testing_prices.html
Redirect 301 legislation.html /PAT_legislation.html
Redirect 301 testimonials.html /PAT_testimonials.html
Redirect 301 faq.html /PAT_faq.html

Reason why I ask this is because if you go on google and type in :

pat tester bromsgrove

and then click on the 2nd of the visible results in the SERPS for jmillselectrical.co.uk which will have the absolute URL showing jmillselectrical.co.uk/legislation.html , this still throws up a :

"Not Found

The requested URL /legislation.html was not found on this server."

This example of the search query isnt too bad as there is more than 1 instance of the site in the SERPS. When it does cause problems, is when there is only 1 result for the site in the SERPS and its that link which is deceased, so Ive effectively lost a user as they would just carry on searching through the rest of the SERPS on that particular page.

I hope all of the above makes sense…

Ben,

The File Not Found is on your server and the Redirect statements should redirect visitors just as it redirects SEs’ spiders. The 301 is important to the SEs, though, as it tells them to update their database. Time? It will take the SEs weeks to come around to re-spider your website (which could be sped-up SLIGHTLY by registering the pages again).

Regards,

DK