简体   繁体   中英

mod_rewrite with codeigniter

im using shared hosting. i build my web application with codeigniter and my new web directory will be as follows:

/home/projName/public_html/proj_v3/

under this dir, there are index.php, .htaccess. as shown above, i separated different project version in different directories (ie: proj_v1,proj_v2, proj_v3). the web applications allows photo upload and it's stored in /home/projName/public_html/proj_v3/application/uploads . proj_v2 currently has the latest uploaded photo since it's still in use. because i have different version of projects, i want to place directory uploads in a common directory such as /home/projName/public_html . so that for any new version of projects, i won't have to move the upload folder to the new project folder. this might cause downtime.

currently, the .htaccess file in /home/projName/public_html/proj_v2 is:

Options -indexes
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1/ [L]

i have another .htaccess in /home/projName/public_html/ is:

Options All -Indexes
RewriteEngine On
Rewriterule ^(.*)\.*$  proj_v3/index.php/$1/
RewriteOptions MaxRedirects=3 

basically how should i go about editing the 2nd .htaccess file in /home/projName/public_html/ so that if the web directory is domain.com/uploads/image.png , it gets the image from /home/projName/public_html/uploads . currently, the 2nd .htaccess file tells domain.com to point /home/projName/public_html/proj_v3

RewriteRule \.(jpe?g|gif|png|wmv|bmp)$ /uploads/$1

Might work for you. You can add other formats as needed.

What you want to do is allow the paths to real files and folders to exist, while redirecting everything else to CodeIgniter, and you can achieve this using this in your second .htaccess file:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

Definitely worth reading this article on the CodeIgniter website about mod rewrite

I actually gave a similar answer before: mod_rewrite in Users/<username>/Sites directory on OSX

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM