php - codeigniter public directory in url -


in example:

- index.php - /system - /application    - /controller       - test.php (class:test ; function index() ; echo "hi") - /public    - style.css 

i point browser http://mysite.com/ show "hi"

if want style.css, must point http://mysite.com/public/style.css

but want point http://mysite.com/style.css can show style.css too

i tried move index.php public add prefix ../ before system , application

also setup htaccess in root directory,then can point http://mysite.com/style.css style.css

but there's problem,i can't point test controller anymore,it show error 404

how can keep both url?

update:

htaccess in root dir:

rewriteengine on rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d  rewriterule ^public/.+$ - [l]  rewritecond %{document_root}/public/$0 -f rewriterule ^.+$ /public/$0 [l]  rewritecond $1 !^(index\.php|images|robots\.txt) rewriterule ^(.*)$ index.php/$1 [l] 

when visit http://mysite.com/style.css can show style.css

but controller test in not work,i visit http://mysite.com/test/test/index show 404 not "hi"

you can test rewritecond if requested file public directory

# prevent requests public directory being rewritten rewriterule ^public/.+$ - [l]  rewritecond %{document_root}/public/$0 -f rewriterule ^.+$ /public/$0 [l] 

you must insert rule before codeigniter rule, because otherwise file rewritten /index.php/....

update:

first, must leave out rewritecond !-f/!-d.

the url test/index must http://mysite.com/test/index or http://mysite.com/test.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -