views:

45

answers:

4

I have the following rewrite rules:

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteBase /

  # Route requests to /media/* to /projects/media/*
  RewriteRule ^media/.* - [NC,L]

  # Route all URLs to dispatch.php.
  RewriteRule ^(.*)$ dispatch.php [L]
</IfModule>

This redirects everything to dispatch.php, unless the URL is example.com/media/* in which case it will look for the requested file in ./media/. I would like the URL /media/* to be rewritten to look in project/media/*.

Using the rewrite rule RewriteRule ^media/.* project/media [NC,L] results in everything going to dispatch.php.

A: 

You'll need to capture the path and append it. Such as:

RewriteRule ^media/(.*)$ project/media/$1 [NC,L]
mopoke
I've already tried this and it results in everything being rewritten to dispatch.php
Pheter
A: 

Try these rules:

RewriteRule ^media/.* project/$0 [NC,L]
RewriteRule !^project/ dispatch.php [L]
Gumbo
This rule doesn't work. Also I would like to route /media/ to the directory /projects/media.
Pheter
A: 
RewriteEngine on
RewriteBase /
# Route requests to /media/* to /projects/media/*
RewriteRule ^media/(.*)$ project/media/$1 [L]
# Route all URLs to dispatch.php.
RewriteCond %{REQUEST_URI} !^/project/media/.*
RewriteRule ^(.*)$ maintenance.php [L]

Originally I wanted to use the special %{IS_SUBREQ} variable, but I couldn't get it working.

Simone Carletti
A: 

Solution can be found here.

Pheter