For the first part (first rewrite rule) try
RewriteCond %{REQUEST_URI} !portfolio/project RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png)$ [NC] RewriteCond %{REQUEST_URI} /.*portfolio/.*$ [NC] RewriteRule ^(.*)portfolio(.*)$ /$1portfolio/project$2 [R=301,L]
I'm not sure why you are using RewriteCond $1 !\.(gif|jpe?g|png)$ [NC] in the second rewriter.
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png)$ [NC] means that you do not want to modify the portfolio in the portfolio / project for URLs ending with some permitted extension. [NC] (case insensitive) is used to skip JPG, GIF, PnG, etc. Besides,
source share