Forum Moderators: phranque
img/
.htaccess
image.php
index.html
Now, I have the following in my HTACCESS file:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([a-z0-9_-]+)/?([a-z0-9_-]+)?/?$ image.php?user=$1&template=$2 [NC,L]
This will rewrite any combination of the following:
/sample/test
/sample/test/
/sample
/sample/
To image.php?user=sample$template=test (unless you don't include test). Which is exactly what I need. However, if I attempt to go to
[sample.com...]
it will redirect me to image.php?user=img
How do I keep it from redirecting ACTUAL directories?
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([a-z0-9_-]+)/?([a-z0-9_-]+)?/?$ image.php?user=$1&template=$2 [NC,L]
Unless there's some way of making this more efficient.
Make the RewriteRule pattern as specific as possible, so that the CPU-intensive "exists" checks only run when absolutely required (RewriteConds are only processed if the RewriteRule pattern matches). These checks must call the file system, and depending on caching, may invoke a physical disk read, so avoid them at all costs, especially on busy and/or shared servers.
Jim
Thanks for the heads-up about -l, I'll remove that. I have never used file checks before, so I went ahead and used all three "just in case".