Question

Thanks in advance.

What I am trying to do is rewrite anything with the word "assets" and simply tack on the /projects/ to the beginning. Then rewrite everything else to my index.php file.

So, /phantom-hearts/assets/pdf/cabbot-story.pdf /allyson-darke/assets/jpg/image1.jpg

becomes /projects/phantom-hearts/assets/pdf/cabbot-story.pdf /projects/allyson-darke/assets/jpg/image1.jpg

Then, rewrite everything else to my index.php file.

Here is my .htaccess file

Code:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

#rewrite project assets
RewriteCond %{REQUEST_URI} !/assets$
RewriteRule (.*)/assets(.*) projects/$1/assets$2 [L]

#rewrite everything else
RewriteRule .*          index.php/$0    [PT,L,NC] 

Both of these rules work fine on their own and this file works in a few htaccess online testers I've tried, but when I try them on my localhost, I get Internal Server Errors.

Any ideas? What am I missing? Thanks a lot.

Was it helpful?

Solution

You can use:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#rewrite project assets
RewriteCond %{REQUEST_URI} !/assets
RewriteRule (.*)/assets(.*) projects/$1/assets$2 [L]

#rewrite everything else
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L,NC] 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top