Apaches mod_rewrite VS. PHP routing?

2019-06-18 15:51发布

问题:

for some days now I have been trying to make a simple mod_rewrite rule to create friendly URLs, my web host have mod_rewrite enabled but I just can't get it to work.

All the next questions where posted by me:

  1. .htacces to create friendly URLs
  2. Friendly URLs with .htaccess
  3. .htacces NOT working…

None of the answers worked, so I'm thinking now using simple php routing instead and I wanted to know if there is a big performance or SEO difference between the two. And if there is, maybe you know how to fix the mod_rewrite problems posted in my questions.

Thanks.

回答1:

If you're using PHP routing for PHP files only, it would be no problem performance-wise: The interpreter will get started anyway, a new process started, memory allocated etc.

But if you are planning to route requests for static resources like images and style sheets as well, however, don't use PHP routing under any circumstance. It's way too resource-intensive and not what PHP was built for.

I'd say mod_rewrite is the better, leaner solution and it's worth trying to figure it out.



回答2:

I prefer routing that kicks in when the requested file doesn't exist, like this in Lighttpd:

server.error-handler-404 = "/index.php"

Provided you find out how to do this in Apache, your script would be more cross webserver compatible, since Apache's mod_rewrite conditions in .htaccess won't work on Lighttpd.