I have created application in codeigniter.Both Front end and Back end.
My Folder Structure is
Pariwar -> Root
---- css
---- js
---admin
---- .htaccess
---- index.php
---- css
---- js
--application
----admin
---- views
=--- models
---- controllers
----Front
---- views
=--- models
---- controllers
I have created the structure using
http://webduos.com/create-an-admin-panel-with-codeigniter/.
when I accessing Front end using
http://localhost/Pariwar/ all working fine.
But when I trying to accessing back-end using
http://localhost/Pariwar/admin/ the css and js are not loading and showing error.
I have set $config['base_url'] = 'http://localhost/Pariwar/'; for Front End
$config['base_url'] = 'http://localhost/Pariwar/admin/'; for back end.
Also made proper changes in index.php file.
Also my .htaccess file is
RewriteEngine on
RewriteCond $1 !^(index.php|images|css|fonts|js|uploads|upload|img|floorplan|mainslider|projectslider|robots.txt)
RewriteRule ^(.*)$ http://localhost/Pariwar/index.php/$1 [L] for front folder
And
RewriteEngine on
RewriteCond $1 !^(index.php|images|css|fonts|js|uploads|upload|img|floorplan|mainslider|projectslider|robots.txt)
RewriteRule ^(.*)$ http://localhost/Pariwar/admin/index.php/$1 [L] for admin.
Please help me to solve this issue.
You need to place all those css and js files within root folder only from there you can access your files within codeigniter
--application
--system
--admin
--public
--js
--imgs
--css
Then using a helper function as:
application/helpers/utility_helper.php:
function public_url(){
return base_url().'public/';
}
and within your application/config/autoload.php:
$autoload['helper'] = array('url','utility');
You will then have access to asset_url() throughout your code.
You only need one .htaccess file at the root of your application.
The second .htaccess file in the admin folder is assuming that there is an admin sub-folder within the admin folder.
Create one .htaccess file at the root of your applications and set your rules here.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Removes access to the system folder.
#Additionally this will allow you to create a System.php controller,
#‘system’ can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn’t true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This last condition enables access to the images and css folders, and the
robots.txt file
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
Consider reading up on mod_rewrite documentation to learn more about Apache mod_rewrite rules
Related
I was wondering, how i could give access to the public to files placed within a folder called 'Sample' which is placed inside /applications/views/ .
I tried to to do it using .htaccess file.
This is the .htaccess file that im using right now.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /0.9.1
#Removes access to the system folder by users.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
#Checks to see if the user is attempting to access a valid file,
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#Enable access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|application\views\Sample\/public)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Any help would be appreciated. Thank you.
Are you placing your images, css, js etc in your application folder? If you are stop right there. The application and system folder don't allow direct script access and it should be kept that way. Anything you want to make public you should put into a folder called something like public and place that in root directory alongside your application and system directories.
I am running into an odd pathing problem in CodeIgniter/MAMP Pro. I enabled nice URLs in CodeIgniter (hid index.php from URL) by setting $config['index_page'] = ''; in config.php and by adding the following to .htaccess:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|js|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
My app was working fine, however I am not able to hit my CSS and JS files for some reason. If i type in http://mysite:8888/js/jquery.js I get a CodeIgniter 404 page. Any idea on why this might be the case?
I use this .htaccess for CodeIgniter projects on MAMP. It supports subfolders too:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
.htaccess files are read dynamically and should not need a MAMP restart, unless you adjusted apache's setting files in it's essence.
The robots.txt is not really secret file, so it's not really of importance to mask it out.
The scripts/images/etc. folders you should just add an index.html file, like CodeIgniter does in it's systems folder too. This way users can't browse those folders. Don't forget to copy index.html files into the subfolders too tho. This may seem dirty, but will be a lot cleaner than cluttering your htaccess with even more rules.
I think the above answer is good, but since CI is dynamically writing URLs, I prefer this method. Also, I think this helps with writing better template code. (I tested this specifically on MAMP.)
For one, set the .htaccess file to the following:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Create a new helper in application/helpers. I call mine assets_helper.php but call it whatever is useful. Put this code in that helper file:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if ( ! function_exists('asset_url()')) {
function asset_url() {
echo base_url().'assets/';
}
}
Add the helper to your autoload file in config/autoload.php a la
$autoload['helper'] = array('url', 'assets');
(You may not already have the url helper activated, but it's common.)
And also add a route for the assets folder (in config/routes.php):
$route['assets/(:any)'] = 'assets/$1';
Now when you want to add css, or js or images, you just need to put <? assets_url(); ?> in the template code.
<img src="<? asset_url(); ?>images/logo.png" width="100" height="100" />
or
<link rel="stylesheet" href="<? asset_url(); ?>css/house.css">
I'm building my website in codeigniter, and here an example of a routing rule that's giving me some trouble:
$route['updategamepage/(:num)'] = 'maincontroller/main/updategamepage/$1';
So is there anything wrong with the format/structure of the rule? Here is an example url that uses that rule:
http://www.mydomain.com/ci_website/updategamepage/6
and when that page gets loaded, the css/js don't get loaded with the page...any idea on whats going wrong?
Your routing rule should only apply to things that get routed through CodeIgniter's index.php file. That routing is dictated by the application's .htaccess file. It's possible that your htaccess is redirecting requests to your .css file to CodeIgniter when you don't want it to.
Ultimately you may way to check your web server logs, including potentially enabling mod_rewrite logging, to see what's actually going on.
Here is an example .htaccess that I use for my CodeIgniter apps:
(Notice you will have to change the RewriteBase directive near the top)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /app/
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
Here's a short .htaccess snippet I always use in my projects, it's much easier to understand.
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|shared|uploads|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]
what it does is that it redirects every url that doesn't contain index.php, assets, shared, uploads and robots.txt right after the URL to your public folder to your index.php file allowing you to set your $config['index_page'] value to '', that will make your URL's much more pleasant for the eye and search engines. Without this you had URL's like http://www.mysite.com/index.php/pages/about, with it you will have http://www.mysite.com/pages/about.
Personally I keep my JS and CSS files in assets folder, but if you like to keep them in the root folder, simply add their folder names to the second line of the .htaccess file I provided separated with a | sign
RewriteCond $1 !^(index\.php|js|css|shared|uploads|robots\.txt)
As I suggested in my answer to your other question a few minutes ago, you better erase the contents of your $config['base_url'] value and let CodeIgniter do the job for you - he does it really well.
I am new to CI and don't know much about rewrite rules. I was able to find htaccess rules from stackoverflow post which allows me to remove index.php from the URL. The ht access rules are as following
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /siebeluigen/
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
But this doesn't work if I move my controllers to subfolder within the controller directly. for example
If I put my Application controller in following path
application/controllers/application.php
Then I can access it from URL
http://localhost/siebeluigen/application
But if my directory structure is
application/controllers/app/application.php
Then I get error with following url
http://localhost/siebeluigen/app/application
but it works like this
http://localhost/siebeluigen/index.php/app/application
So, I am pretty sure there is something in htaccess that I should be able to change to make it work.
Please help!!!
Update
My htaccess file was in the application folder instead of root. Moving the file to the folder were index.php is located solved the issue. I have marked the answer that is working.
Thanks...
This is my htaccess file that I use on ALL my projects:
Options -Indexes
Options +FollowSymLinks
# Set the default file for indexes
DirectoryIndex index.php
<IfModule mod_rewrite.c>
# activate URL rewriting
RewriteEngine on
# do not rewrite links to the documentation, assets and public files
RewriteCond $1 !^(images|assets|uploads|captcha)
# do not rewrite for php files in the document root, robots.txt or the maintenance page
RewriteCond $1 !^([^\..]+\.php|robots\.txt)
# but rewrite everything else
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 index.php
</IfModule>
Then - also make sure that inside your config.php file
$config['index_page'] = '';
edit: you NEVER want to point someone to your application folder - you ALWAYS point them to your index.php - EVERYTHING goes through Index.php - and it does the re-routing to where it is needed.
This is the condition that is usually meant to redirect to application.php
RewriteCond %{REQUEST_URI} ^application.*
app/application doesn't match this condition. Try changing it to this:
RewriteCond %{REQUEST_URI} ^app/application.*
I want to create a website where the main pages will be served from CodeIgniter. I will use Wordpress in the /blog/ sub-directory to host the blog. Thats it! I want nothing else. Just to make sure that:
example.com/somepage/ calls a CI controller where as example.com/blog/some-post/ is handled by Wordpress.
I don't need any kind of integration or interaction between CI and WP.
Is it possible to install in that way? If not, any workarounds so that I can achieve the objectives?
Thanks and Regards,
Masnun
I suspect you could get this to work using an .htaccess file in the root directory of your site. If blog is the name of the subdirectory where WordPress is installed, and you want example.com/blog to be handled by WordPress, try this to see if it helps:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|blog)
RewriteRule ^(.*)$ /index.php/$1 [L]
+1 with Rich's method
Additionnaly, if you're using a .htaccess file like the one suggested on CI doc, it should work by dropping WP directory directly into web root dir.
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This last condition enables access to the images and css folders, and the robots.txt file
#Submitted by Michael Radlmaier (mradlmaier)
RewriteCond $1 !^(index\.php|robots\.txt|corporate|assets)
RewriteRule ^(.*)$ index.php/$1 [L]
Because of the RewriteCond %{REQUEST_FILENAME} !-f and RewriteCond %{REQUEST_FILENAME} !-d any call made directly to a real file on webserver would be served directly by Apache, other uris wil be handled by CI's routing mecanism.
Notice we used a last RewriteCond directive to exclude calls to certains files, including our assets dir (containing images/css/js static files) and 'corporate' dir which contains in this case a blog.
Although this example do not use wordpress, it has its own url-rewriting and routing system.
In a matter of conclusion, you'll have use a specific RewriteCond statement if you want to use WP url-rewriting, if not it could work without it.
It should work just as you described it without any complicated configuration. Just install codeigniter in your root directory and then create a blog directory and put wordpress in there.