Forum Moderators: phranque

Message Too Old, No Replies

RewriteCond and RewriteRule HELP

RewriteCond and RewriteRule HELP

         

s0h31l

3:27 pm on Jul 9, 2008 (gmt 0)

10+ Year Member



Hi everybody

i was wondering whats wrong with this :

RewriteCond $1 !-d
RewriteCond $1 !-f
RewriteRule ^([a-zA-Z0-9_.]{4,32})/?$ file.php?s=$1 [L]

i want this works for every request except the ones that are actually exists...

for example something like :
domain.com/favicon.ico (which exists on the domain) redirect it to file.php which i dnt want to

any ideas ?

jdMorgan

3:41 pm on Jul 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You are trying to test to see if a URL-path exists in your filesystem -- and that is impossible.

The URL-path will never contain the full filesystem path, for example "/var/www/public/html/script.php"

You will at least need to prepend the documentroot filepath for this to work. For example:


RewriteCond %{DOCUMENT_ROOT}/$1 !-f

It is often very helpful when testing "-d" and "-f" checking code to temporarily change the rule to generate a redirect, and then 'display' the filepaths as 'fake' script variables. For example:

RewriteCond %{DOCUMENT_ROOT}/$1 !-d
RewriteCond %{DOCUMENT_ROOT}/$1 !-f
RewriteRule ^([a-zA-Z0-9_.]{4,32})/?$ http://example.com/file.php?s=$1&[i]checkpath=%{DOCUMENT_ROOT}/$1[/i] [R=302,L]

Jim

s0h31l

4:02 pm on Jul 9, 2008 (gmt 0)

10+ Year Member



thx jim for ur reply.. i got everything but can u explained what do u mean by :
"It is often very helpful when testing "-d" and "-f" checking code to temporarily change the rule to generate a redirect, and then 'display' the filepaths as 'fake' script variables. "

g1smd

5:12 pm on Jul 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Try the bit of code that was posted. Enter a test URL in your browser and see that you are redirected to some URL, but that URL contains parameters on the end showing you the values that the redirect is working with. Once you can see what the values actually are, you can make the right rule for your site.

s0h31l

6:51 pm on Jul 9, 2008 (gmt 0)

10+ Year Member



ow i got it ;)

thanks man ;-)

it worked :-)