1

Previously was using command ln for create virtual folder.

cd public
ln -s ../app/assets/ assets

~ public > ls -l
lrwxr-xr-x  1 carlosmontalvo  admin   14 May 15 12:21 assets -> ../app/assets/

But I want to do with mod_rewrite

I tested with

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?assets(.*) ../app/assets$1 [P] #here
RewriteRule ^(.*)$ index.php [QSA,L]

but this does not work

Tree Directory

├── app
│    └─ assets
│       ├── images
│       ├── javascripts
│       │   └── application.js
│       └── stylesheets
│           └── application.css
├── public
│   ├── 404.html
│   ├── 422.html
│   ├── 500.html
│   ├── assets -> ../app/assets/
│   ├── index.php
│   └── robots.txt

could help me? thanks

zetanova
  • 481
  • 4
  • 11

2 Answers2

0

You can't. RewriteRules can only rewrite to locations within the DocumentRoot. Why would you do this anyway? The symlink solution has less overhead and will therefor be faster than the RewriteRule solution.

rpkamp
  • 811
  • 4
  • 14
  • You've never seen a framework with symlink so I thought it using mod_rewrite – zetanova May 16 '13 at 14:11
  • Lithium (li3) recommends using symlinks for the assets. It has a default build in router that let's PHP serve the requested file for development purposes, but they recommend against that for production as it's a waste of PHP threads. – rpkamp May 16 '13 at 17:38
0

You need to use absolute paths.

Alias /assets/ /www/app/assets/

<Directory "/www/app/assets/">
Require all granted
</Directory>

should work provided Apache can access the files.

There's no reason to use mod_rewrite but:

RewriteEngine On
RewriteCond /www/public/%{REQUEST_FILENAME} !-f
RewriteCond /www/public/%{REQUEST_FILENAME} !-d
RewriteRule ^/assets/(.*)$ /www/app/assets/$1 [L]

should work as well.

MJ Walsh
  • 593
  • 6
  • 11