0

I need to access images, css and js files in my pages, but I don't know write the .htaccess file needed.

I'm using CodeIgniter.

The mine folders hierarchy:

   /cv
    |__ cartao_virtual
    |   |
    |   |__ cms
    |   |   |__ assets
    |   |   |   |
    |   |   |   |__ **css**
    |   |   |   |   |__ **images**
    |   |   |   |
    |   |   |   |__ **js**
    |   |   |   
    |   |   |__ controllers
    |   |   |__ models
    |   |   |__ views
    |   |   
    |   |__ site
    |       |__ assets
    |       |   |
    |       |   |__ css
    |       |   |   |__ images
    |       |   |
    |       |   |__ js
    |       |   
    |       |__ controllers
    |       |__ models
    |       |__ views
    |      
    |__ system
    |
    |__.htacess
    |__ site.php (default CodeIgniter index.php)
    |__ cms.php (default CodeIgniter index.php)

My current .htaccess is:

    RewriteCond $1 !^(cms\.php|cms|assets)
    RewriteRule ^cms$ cms.php [L]
    RewriteRule ^cms/(.*)$ cms.php/$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ site.php/$1 [L]

With it, I just have access to cms and site controllers and your methods, and I want keep so.

I'm imagining something like:

    RewriteEngine on
    RewriteCond $1 !^(cms\.php|cms)
    RewriteRule ^cms$ cms.php [L]
    RewriteRule ^cms/(.*)$ cms.php/$1 [L]

    RewriteCond $1 !^(^cms/assets|site/assets)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ site.php/$1 [L]

    RewriteCond $1 !^(site/assets)
    RewriteRule ^site/assets/(.*)$ cartao_virtual\/site\/assets\/$1 [L]

    RewriteCond $1 !^(cms/assets)
    RewriteRule ^cms/assets/(.*)$ cartao_virtual\/cms\/assets\/$1 [L]

Thanks in advanced.

0

1 Answer 1

2

Anywhere you're rewriting (.*) you'll need the following rewrite conditions to not include real files.

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

Right now you're inadvertently redirecting all traffic whether a file or directory exists or not with the exception of one rule.

Sign up to request clarification or add additional context in comments.

3 Comments

Well .. I managed make work perfectly what I wanted with these rules bellow. I don't tried your solution yet. I'll do it more later, though. But, do you know says me if that that you recommended is one of those very rules that diminish much the performance of the server?
Rules working perfectly: RewriteEngine on RewriteCond $1 !^(cms/assets.*) RewriteRule ^cms/assets/(.*) cartao_virtual\/cms\/assets\/$1 [L] RewriteCond $1 !^(cms\.php|cms) RewriteRule ^cms/(.*)$ cms.php/$1 [L] RewriteRule ^cms$ cms.php [L] continue...
RewriteCond $1 !^(^cms/assets|site/assets) RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ site.php/$1 [L] RewriteCond $1 !^(site/assets) RewriteRule ^site\/assets\/(.*)$ cartao_virtual\/site\/assets\/$1 [L]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.