Jump to content

Recommended Posts

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,

 

Link to comment
https://forums.phpfreaks.com/topic/173922-help-needed-with-htaccess-rewriterules/
Share on other sites

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]

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.

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]

 

 

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$ ?

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.