Redirecting /media/* to /project/media/* and everything else to /dispatch.php

≯℡__Kan透↙ 提交于 2019-12-12 04:47:57

问题


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.


回答1:


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

RewriteRule ^media/(.*)$ project/media/$1 [NC,L]



回答2:


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.




回答3:


Try these rules:

RewriteRule ^media/.* project/$0 [NC,L]
RewriteRule !^project/ dispatch.php [L]



回答4:


Solution can be found here.



来源:https://stackoverflow.com/questions/2010249/redirecting-media-to-project-media-and-everything-else-to-dispatch-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!