Cannot target files in Code Igniter - codeigniter

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]

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

CodeIgniter CSS .htaccess 404 error

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]

Codeigniter - no input file specified

I am a beginner in Codeigniter and I saw a CI tutorial and was just trying to do a simple thing. I downloaded the CI and added this file to controller directory, but it won't work.
<?php
class site extends CI_Controller
{
public function index()
{
echo "Hello World";
}
function dosomething()
{
echo "Do Something";
}
}
?>
When I try to access it using http://..../index.php/site I get the output ... "no input file specified" .... by the way, I named the file site.php
Just add the ? sign after index.php in the .htaccess file :
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
and it would work !
Godaddy hosting it seems fixed on .htaccess, myself it is working
RewriteRule ^(.*)$ index.php/$1 [L]
to
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
I found the answer to this question here..... The problem was hosting server... I thank all who tried .... Hope this will help others
Godaddy Installation Tips
RewriteEngine, DirectoryIndex in .htaccess file of CodeIgniter apps
I just changed the .htaccess file contents and as shown in the following links answer. And tried refreshing the page (which didn't work, and couldn't find the request to my controller) it worked.
Then just because of my doubt I undone the changes I did to my .htaccess inside my public_html folder back to original .htaccess content. So it's now as follows (which is originally it was):
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?/$1 [L,QSA]
And now also it works.
Hint: Seems like before the Rewrite Rules haven't been clearly setup within the Server context.
My file structure is as follows:
/
|- gheapp
| |- application
| L- system
|
|- public_html
| |- .htaccess
| L- index.php
And in the index.php I have set up the following paths to the system and the application:
$system_path = '../gheapp/system';
$application_folder = '../gheapp/application';
Note: by doing so, our application source code becomes hidden to the public at first.
Please, if you guys find anything wrong with my answer, comment and re-correct me!
Hope beginners would find this answer helpful.
Thanks!
My site is hosted on MochaHost, i had a tough time to setup the .htaccess file so that i can remove the index.php from my urls. However, after some googling, i combined the answer on this thread and other answers. My final working .htaccess file has the following contents:
<IfModule mod_rewrite.c>
# Turn on URL rewriting
RewriteEngine On
# If your website begins from a folder e.g localhost/my_project then
# you have to change it to: RewriteBase /my_project/
# If your site begins from the root e.g. example.local/ then
# let it as it is
RewriteBase /
# Protect application and system files from being viewed when the index.php is missing
RewriteCond $1 ^(application|system|private|logs)
# Rewrite to index.php/access_denied/URL
RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]
# Allow these directories and files to be displayed directly:
RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|public|app_upload|assets|css|js|images)
# No rewriting
RewriteRule ^(.*)$ - [PT,L]
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php?/$1 [PT,L]
</IfModule>
One of my Codeigniter apps started returning this error after i restarted my server.
When I checked the Codeigniter error log it says something like:
"...[error] 879#0: *273 FastCGI sent in stderr: "PHP message: PHP Warning: Unknown: open_basedir restriction in effect. File(/pathToWebsiteRootFolder/index.php) is not within the allowed path(s): ".
So I added this:
open_basedir= /pathToWebsiteRootFolder/index.php:
To a user.ini file I created in my website root folder.
And this Solved it.
FYI: Im using an NGINX web server.
However, Its strange because I didn't have to do this for the other Apps on the same server.

xampp redirects

Does anyone has an example how to do a rule in .httpaccess in xampp?
I'm trying to redirect from localhost/test/company.php?name=Abc to localhost/test/company/Abc and I cant seem to find the solution. I followed some examples that I found on the web but none seems to work. I'm putting the .htacces file in the same folder where I have the company.php file. And I have the urlrewrite turned on.
Put the .htaccess file in your application root.
The .htaccess file should have something like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^company/([a-zA-Z0-9\-]+)$ /company.php?name=$1 [L,NC]
Turn on mod_rewrite and restart apache.
Then it should work.

Resources