Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've just updated a website that used .php urls, to a Wordpress 3.1 site, that uses no file type extentions, (custom permalinks).

They have a lot of references in their imported content to an old page ending in .php which now goes to an error 404 page.

My question is this: What is the rewrite rule I should use in my htaccess file that would redirect someone clicking on a link to www.somesite.com/glossary.php#anchor, to www.somesite.com/glossary/#anchor?

Any help gratefully appreciated, S.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Your first order of business should be updating the links in your imported content so that people aren't given links to the old URLs in the first place. This should be pretty easy to do with an SQL replace. For your situation, it'd be something along the lines of:

UPDATE wp_posts SET post_content = REPLACE(post_content, '.php', '/');

You gotta be realy careful with find/replaces though, as they sometimes replace things you didn't anticipate. It's a good idea to back up your DB before doing anything like this.

As for an htaccess fix: it's definitely a good idea to do 301s for the old URLs if you have a lot of inbound links, which translate to SEO value. But the amount of work you put into this should be proportional to the value of those inbound links.

I'm thinking it's not a good idea to try to rewrite ALL .php requests, as Wordpress often needs to make legitimate ones. For example, all requests on the frontend are routed through index.php, and when I tried setting up a rule like the one you asked for, it broke WordPress altogether. Know what I'm saying?

An alternative is to set up individual rules for each page you want to 301. Of course, this might be a bad idea if you have a LOT of links--both because it's a hassle, and could impact performance.

Hopefully someone else has a tricky htaccess workaround for you, but I'm stumped.

share|improve this answer
    
Mant thanks - didn't even think of the mysql replace approach - worked a treat! –  sta777 Apr 14 '11 at 8:42
add comment

As far as I know, the hash at the end of the url (#anchor here) never gets sent to the server. However, if you can just get WordPress to load the correct content when glossary.php is requested, the anchor should work just the same.

MathSmath is right about 301 redirects being important, but I'd suggest running this stuff in WordPress rather than through .htaccess.

Specifically, I'd recommend using the Redirection plugin. It gives you a simple to use GUI to manage all your redirects that WordPress doesn't take care of automatically.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.