Jump to content

Help needed with .htaccess RewriteRules


Rebelrebellious

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.