Rebelrebellious Posted September 11, 2009 Share Posted September 11, 2009 Although the file http://domain.net/public/ico/favicon.ico exists the following instructions give me a 500 when I request http://domain.net/public.ico # allow requests for public files to go through RewriteCond $1 ^/public/ [NC] RewriteCond $1 !^/public/.*/.*\..*$ [NC] RewriteRule ^/public/(.*)\.(.*)$ /public/$2/$1.$2 [N,NC,E=REWRITE:%{ENV:REWRITE}-public/$1.$2] # prevent the request from going to the main program if the file exists in public/ext/ RewriteCond $1 ^/public/(.*)$ RewriteCond %{REQUEST_FILENAME} -f [NC] #RewriteCond $1 -f [NC] RewriteRule .* - [L] # send almost everything to the main program file RewriteCond $1 !^/main\.php$ [NC] #RewriteCond $1 !^/public/(.*)$ [OR] #RewriteCond $1 !-f RewriteRule (.*) /main.php [L,QSA,E=REWRITE:%{ENV:REWRITE}-$1] I've been struggling with this for way too long. Please help, Quote Link to comment https://forums.phpfreaks.com/topic/173922-help-needed-with-htaccess-rewriterules/ Share on other sites More sharing options...
Rebelrebellious Posted September 11, 2009 Author Share Posted September 11, 2009 After making some changes I am now getting my main.php. The main.php should not be coming up because the file favicon.ico should be found after the first rewrite succeeds (which isn't happening) and the second rewrite prevents the third rewrite from happening. Here is the current script: # allow requests for public files to go through RewriteCond $1 ^/public/ [NC] RewriteCond $1 !^/public/.+/.*\..*$ [NC] RewriteRule ^/public/(.*)\.(.*)$ /public/$2/$1.$2 [NC,L,E=REWRITE:%{ENV:REWRITE}-public/$1.$2] # prevent the request from going to the main program if the file exists in public/ext/ RewriteCond $1 ^public/(.*)$ #RewriteCond %{REQUEST_FILENAME} -f [NC] RewriteCond $1 -f [NC] RewriteRule .* - [L] # send almost everything to the main program file RewriteCond $1 !^main\.php$ [NC] #RewriteCond $1 !^/public/(.*)$ [OR] #RewriteCond $1 !-f #RewriteRule (.*) /main.php [L,QSA,E=REWRITE:%{ENV:REWRITE}-$1] RewriteRule ^(.*)$|^$ /main.php [L,QSA,E=REWRITE:%{ENV:REWRITE}-$1] Quote Link to comment https://forums.phpfreaks.com/topic/173922-help-needed-with-htaccess-rewriterules/#findComment-916840 Share on other sites More sharing options...
Rebelrebellious Posted September 11, 2009 Author Share Posted September 11, 2009 So to simplify the problem, I have commented out everything except: # allow requests for public files to go through #RewriteCond $1 ^%{DOCUMENT_ROOT}/public/.+ [NC] RewriteCond $1 !^%{DOCUMENT_ROOT}/public/.+/.*\..+$ [NC] RewriteRule ^public/(.*)\.(.+)$ /public/$2/$1.$2 [NC,L,E=REWRITE:%{ENV:REWRITE}-public/$1.$2] if I request http://domain/public/ I get 403 Forbidden if I request http://domain/public/favicon.ico I get 500 if I request http://domain/public/ico/favicon.ico I get 500 Please help me work through this. Quote Link to comment https://forums.phpfreaks.com/topic/173922-help-needed-with-htaccess-rewriterules/#findComment-916921 Share on other sites More sharing options...
Rebelrebellious Posted September 11, 2009 Author Share Posted September 11, 2009 Okay. I finally got the first part working. Hopefully the rest comes together quickly. # allow requests for public files to go through RewriteCond $1 ^public/(.+)$ RewriteCond %1 ^(.*)\.(.+)$ RewriteCond %1 !^.*/.*$ #RewriteCond %1 !/ RewriteRule ^(public/.+)$ public/%2/%1.%2 [NC,L,E=REWRITE:%{ENV:REWRITE}-$1] Quote Link to comment https://forums.phpfreaks.com/topic/173922-help-needed-with-htaccess-rewriterules/#findComment-916954 Share on other sites More sharing options...
Rebelrebellious Posted September 11, 2009 Author Share Posted September 11, 2009 So at this point it is mostly working. RewriteCond $1 ^public/(.+)$ RewriteCond %1 ^(.*)\.(.+)$ RewriteCond %1 !^.*/.*$ #RewriteCond %1 !/ RewriteRule ^(public/.+)$ public/%2/%1.%2 [L,E=REWRITE:%{ENV:REWRITE}-$1] # send almost everything to the main program file # prevent the request from going to the main program if the file exists in public/ RewriteCond $1 !^public/.*$ RewriteCond $1 !^main\.php$ RewriteRule ^(.*)$ /main.php [L,QSA,E=REWRITE:%{ENV:REWRITE}-$1] Is there any way to do away with RewriteCond $1 !^main\.php$ ? Quote Link to comment https://forums.phpfreaks.com/topic/173922-help-needed-with-htaccess-rewriterules/#findComment-916975 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.