Reputation: 61
I have been testing regex and come to a conclusion that this is most efficient performance killer ever invented.
My problem is that i need better urls for my site and the only right way to do it seems to be Apaches Rewriterule, but it requires to be used with regex and i would like to avoid this.
Anyone know if its possible to avoid using regex and if yes then how to do it ?
what im using right now in .htaccess is:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
How do i get rid of regex ?
Upvotes: 0
Views: 510
Reputation: 1245
If you know in advance which URLs you want to redirect, I should use Redirect rather than Rewrite rule. Redirect doesn't have regexps, but that means that you need to specify each URL that you want rewritten, e.g.
Redirect /BadUrl http://myhost.com/GoodUrl
But if what you want is to have an infinite number of now-nonexistent pages be redirected by Apache to a new URL scheme, I'm afraid that you're stuck with regexps. I should, however, agree with Gerben that it's more likely that the IO is slowing the server down rather than the regexp itself - I'm working with systems which have millions of requests per day, and it's not the rewrite rules that's our main performance issue...
If the basic Redirect doesn't work, and you don't want to use the mod_rewrite functions, I'd suggest moving the redirect logic entirely out from Apache. Since you're already using PHP, you could simply replace the normal 404 file with a PHP script that rewrites the URL to your desired URL scheme. It would also give your users a chance to update their bookmarks.
Upvotes: 2