htaccess codeigniter mod-rewrite, rewritecond to ignore subdirectory within main app directory

为君一笑 提交于 2019-12-12 01:02:05

问题


I have an install of codeigniter up, running and all is good. Except I want to now offer my users a means of uploading images. The only place I could think to put the folder was in the applications directory (aptly renamed to "app" in my case). Anyway. Since its an MVC I need to run rewrite conditions all over the place. And I believe this to be one of the scenarios.

What I need is to have a condition that works for this subfolder within the app folder

my original rewrite condition is

RewriteCond $1 !^(index\.php|static|robots\.txt)

which works great for those but not for this one case so I need a new condition that works with the above but supports app/upload (is this even possible)?


回答1:


Life's a lot easier if you keep your assets outside of application/ (as Robert mentioned).

There are a ton of good asset management Sparks you can pick from to assist with this too - I authored one for my CI projects called sk-asset which provides a lot of view helpers & is structured:

  • /CIAppRoot
    • assets/
      • css/
      • download/
      • img/
      • js/
      • less/
      • swf/
      • upload/
      • xml/
    • application/
    • system/

... htaccess settings can simply bypass CI routing for existing files/dirs/etc:

<IfModule mod_rewrite.c>
  Options +FollowSymlinks
  RewriteEngine On

  # block hidden directories
  RewriteRule "(^|/)\." - [F]

  RewriteCond $1 !^(index\.php|assets|robots\.txt|favicon\.ico)
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
</IfModule>



回答2:


The upload folder does not have to be in your application directory. In fact, it's better if it's not in it. This way you can separate the application from the content (uploads). You also don't need to rewrite the conditions if you do it this way. This is how my CI directory looks like:

/application
/assets
/uploads
/system     


来源:https://stackoverflow.com/questions/11240911/htaccess-codeigniter-mod-rewrite-rewritecond-to-ignore-subdirectory-within-main

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