Redirecting /media/* to /project/media/* and everything else to /dispatch.php
I have the following rewrite rules:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
# Route request开发者_StackOverflow中文版s 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.
You'll need to capture the path and append it. Such as:
RewriteRule ^media/(.*)$ project/media/$1 [NC,L]
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.
Try these rules:
RewriteRule ^media/.* project/$0 [NC,L]
RewriteRule !^project/ dispatch.php [L]
Solution can be found here.
精彩评论