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.
Related
I have an issue with my .htaccess.
Let's say that my app folder are:
/APP/
/CONTENT/
/UPLOADS/
/ASSETS/
And I have a .htaccess file that point all requests to my index.php, and the index php there is an included file called router.php that manage my roots:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\s\S]*)$ index.php?url=$0 [QSA,L]
What i would want to do right now is to point APP and CONTENT folder also to the .htaccess and like that, i can display my custom 404 error page.
I recently moved my index.php (the file that handles routing) and CSS, JavaScript, and font assets to a public/ folder. I only want items in this public/ folder to be accessible for security purposes. I ran into this problem when I realized I could visit mysite.com/composer.lock and view the composer lock file with my old .htaccess and folder setup.
Here is what I want
If I visit mysite.com/car/create, I want it to actually point to mysite.com/public/index.php?path=car/create
If I link to an asset such as mysite.com/css/style.css, I want it to really point to mysite.com/public/css/style.css
Here is my folder structure
Here is my .htaccess which is not working at all
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ public/index.php?path=$1 [L,QSA]
</IfModule>
How can I fix this? It just generates empty pages and I can still directly visit files in the root directory, etc.
Your existing directives specifically avoid rewriting requests for existing files, so it would still enable you to visit files in the root directory. It will also rewrite static resources to public/index.php?path=, which will presumably fail.
Try the following instead:
RewriteEngine On
# Stop processing if already in the /public directory
RewriteRule ^public/ - [L]
# Static resources if they exist
RewriteCond %{DOCUMENT_ROOT}/public/$1 -f
RewriteRule (.+) public/$1 [L]
# Route all other requests
RewriteRule (.*) public/index.php?path=$1 [L,QSA]
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
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 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.