CodeIgniter CSS .htaccess 404 error - codeigniter

I am building an admin section in codeigniter for my site and wanted to have a separate CSS folder for the CSS files for the admin section as they are going differ to those for the main site.
Current my CSS files sit in assets/css
I added and extra folder to that called admin and placed my new CSS files in that ie
assets/css/admin/css/style.css
However when I click the link in source code view to that stylesheet, I get a 404.
My current .htaccess reads as follows:
RewriteEngine On
RewriteCond $1 !^(index\.php|assets|editor|css\/|admin|js|scripts|images|img|media|xml|user_guide|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
What would I need to do to enable this file.
Note the strange thing is I have 4 CSS files in the folder, two of them whem clicked in the view source ope okay, and 2 of them contain the 404.

use this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

Related

Redirect laravel installation in a subfolder, hiding the subfolder

Let's say i have installed laravel on a subfolder: i placed all the app stuff outside the html root, renamed the "public" directory in "laravel" and moved under the html root.
I can see the app by connecting to www.mydomain.com/laravel
I used the following .htaccess in the root html folder:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
RewriteCond %{REQUEST_URI} !^/laravel/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /laravel/$1
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
RewriteRule ^(/)?$ laravel/ [L]
Now i can access my site directly from www.mydomain.com
But i see that i can still access it from www.mydomain.com/laravel ... and since all the links are generated starting from the base url, the menu and every anchor href points to www.mydomain.com/laravel... even the canonical link of the pages contains "laravel".
Questions:
is there a way to avoid this??
should i worry for this?
Thanks for help.
If you are using apache, you need to configure your hosts. Either http-vhosts.conf or httpd.conf or similar file.
<VirtualHost >
...
<Directory "path/to/your/root/html/laravel">
</Directory>
</VirtualHost>
So all you need to do is change the directory path to point directly to your laravel folder inside of html directory.
If you do that, remove the lines you added in the .htaccess
RewriteCond %{REQUEST_URI} !^/laravel/
...
RewriteRule ^(/)?$ laravel/ [L]
And place the .htaccess file back in laravel directory so it can serve page directly from there.

How do I exclude stylesheet and javascript files from my rewrite rules?

I have a rewrite rule currently as shown below:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)$ $2.php?locale=$1 [QSA,L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+) $2.php?page=$3&locale=$1 [QSA,L]
My page URLs are like this:
http://example.com/en/new
or this:
http://example.com/en/new/1
As for the index page it's like this:
http://example.com/en/index
and I wanna get rid of the 'index' word so I added this rule:
RewriteRule ^(.*)$ index\.php/$1 [L]
Which works as expected except for my web assets (css, js files) which are located under: /css and /js folders now has 500 error. So my question is how to I exclude URLs pointing to these files under these 2 directories from being rewritten.
This solved my problem. Either use the suggested answer from here
http://stackoverflow.com/questions/1848500/htaccess-mod-rewrite-how-to-exclude-directory-from-rewrite-rule?rq=1
or simply create a .htaccess file inside the directory where you don't want rewriting to take place and put this in:
RewriteEngine Off

Cannot target files in Code Igniter

Hello I have created a new subdomain of my domain and I am building a code igniter application. Everything is working OK except the fact that I cannot target the stylesheet or any other file in the application.
I have structure like this:
Root
/application
/css
/images
/js
/system
/userguide
Inside the css folder I have a style.css file.
I have tried to add this stylesheet to my application and it is not possible.
The strange thing is that even when I the url directly in the browser it sais that it cannot find the file.
I am on Bluehost, not sure if that has something to do with the configuration of the server or the configuration of the codeigniter.
Please help as I have tryied every possible method.
Thanks to all in advance!
Change your htaccess file to
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|js|robots\.txt|favicon \.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]
This is standard which i have been using in my many CI Apps and it works fine :)
Also this htaccess file should be alongwith application, system folder(outside application folder)
Insert following line in your html file:
<link href="css/style.css" rel="stylesheet">
Double check that you have copied the file with correct name in css folder.
I assume that your other settings are correct.
At first it should be better to put images, css and js folders in a folder named "public" on the root.
Then you can use this code:
<LINK href= "<?=site_url(); ?>public/css/style.css" rel="stylesheet" type="text/css">
Another way you can include a css file is by using the template library.
If the problem insists then you may change your root .htaccess file like this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
I have managed to resolve my own problems after reading the links that Jigar pointed me to.
My solution is to add in the htaccess file of the root:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

.htaccess URL rewriting for CodeIgniter not working

I have the following .htaccess in /home/domain/public_html/subfolder
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|user_guide|robots\.txt)
RewriteRule ^(.*)$ public/index.php?/$1 [L]
But this doesn't work http://domain.com/subfolder/
File does not exist: /home/domian/public_html/public
I apparently have my rewrite rules messed up. This entire CI application is in a subfolder of the web root.
/home/domain/public_html/subfolder
[sssss#ff subfolder]$ ls
application license.txt public system user_guide
and index.php is in public.
First, your index.php should be in the same directory as application and system.
Once you moved it, try this in your .htaccess
RewriteEngine on
RewriteBase /subfolder/
RewriteCond $1 !^(index\.php|user_guide|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]
Also on an unrelated note, I'd delete the user-guide directory since everything it contains is accessible at on the CodeIgniter Site.

how do i get to restrict access to my folders

am using codeigniter to build a website with a lot of image galleries , i store the images in folders ,but i want to restrict access to the folders via url .i.e i don't want people to have access to my image folder using a url like this::
http://website/all_images/
all images is the folder that contains the image folder .. i tried using a htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^CI_system.*
RewriteRule ^(.*)$ /website/index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|all_images)
RewriteRule ^(.*)$ /website/index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
the rewrite condition for the index.php works well but i still get access to all my folders via the url
If you want to disable folders to be viewed, just add empty index.html file, but if you try to protect images from being viewed then your website wont be able to find them too
Why don't you create an index file under that folder. In this way no will will be able to view images under that folder.
You can make this file call a function that says "access denied" or whatever you need.
Options -Indexes in your htaccess file will stop directory viewing no extra files needed. and if you want to stop direct image viewing i.e. myweb.com/all_images/coolpic.jpg then all you have to do is (since your base is / you can use the whole one below):
Options -Indexes
ErrorDocument 404 /index.php
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?myweb.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ - [F]
</IfModule>
All you would have to change is the line with your web address in it and add all of your file types to the last rewrite rule (seperating each with a pipe |) and then this will cover all of the angles you have discussed 100%.

Resources