Oleh Prypin
Oleh Prypin

Reputation: 34116

Using PHP script to assist .htaccess mod_rewrite

I'm planning to use large amounts of URL rewrites on my website, but I can't get familiar with Apache's mod_rewrite because it's difficult and poorly documented.

I heard there's some option that allows invoking various scripts for the rewriting purpose. Can you help me with it?

Upvotes: 0

Views: 946

Answers (2)

Pekka
Pekka

Reputation: 449385

Don't do it, at least not indiscriminately. You can redirect any request to PHP and do the parsing there. It's a tempting option, but it's horrible for performance because there's an expensive PHP process started for every request to every resource, including images, style sheets and so on.

Only when there is a lot of URL rewrites (like dozens, hundreds or thousands after a site move o restructuring) it may make sense to redirect them to a PHP script that does a database lookup. But even then you should know the basics of mod_rewrite in order to decide which requests to redirect to that script.

mod_rewrite is very finely documented, it just takes some getting into. I recommend at learning the basics.

One good resource to get started is this blog entry. There are numerous good questions on SO as well that are full of examples. The official docs are here.

Upvotes: 7

Sander Marechal
Sander Marechal

Reputation: 23216

You can use RewriteMap to call an external program. But, as Pekka said in his comment, you better not do this. It just makes it more complex and fragile. mod_rewrite is one of the best documented modules around and there are tons of tutorials, raging from simple to complex. I have done big website moves with many, many pages and a completely restructured URL schema. Even these can usually be done with a couple dozen rewrite rules or so.

Start with the rewrite guide.

Upvotes: 2

Related Questions