I want to block assets folder path in Codeigniter - codeigniter

Am new in Codeigniter i want to block assets folder in my website. I mean website users(website viewer) enter http://www.example.com/assets it move to 404 page.
Please help me...!
Thanks in advance

If your assets folder is there to serve things like CSS, JavaScript and image files (like would be intended), and is an actual directory, then you can either do this by adding a .htaccess file to the directory (assuming it's running under Apache) which will take all requests which are not for explicit file paths and route them to the website controller/action for a 404 (or other page you use for this).
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ http://yourdomain.com/path/to/404 [QSA,L]
</IfModule>
Alternatively, you can add an index.php file which redirects the browser to the location for a 404 page, or displays a 404 type page as a response.
header("Location: http://yourdomain.com/path/to/404");

Related

rewrite url only and stay on the same page

I have read a lot on stack about rewriterule and how it applies and I've tried reading up on some good articles online but I still cannot wrap my head around a few things.
I have blogs setup where all folders are in
https://domain.ca/posts/post-tree/*
So I've setup htaccess like this
RewriteRule ^posts/post-tree/(.*)$ /index.php?$1 [R=301]
As I'm sure you can guess this basically brings me root index.php where I catch this request with a $_GET to know the name of the blog folder it was requesting.
This is fine I can hit index.php and with $_GET I know the blog page they requested.
What I do not get, and I've tried a lot of things, is once I have this request in index.php how do I re-write the URL to show something like https://domain.ca/blogpage/ instead of looking like https://domain.ca/index.php? where https://domain.ca/blogpage/ does not really exist of course, but it is because I want to hide the http://domain.ca/posts/post-tree/ path.
Its a little like when wordpress processes a blog page with the id and after rewrites the url to whatever slug is set for that blog page. at least my understanding of it as they don't have individual folders for blogs, but I do.
I finally got this working with the following in the htaccess file
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
# the above checks if file or folder exists, if not the below is processed
# this will route to base index file and fetch $1 folder via $_GET
RewriteRule . /posts/post-tree/index.php?$1

How to rewrite URL PrestaShop to hide folder?

I would like to hide my folder where PrestaShop is installed.
To access my shop, I must write http://domain.com/prestashop.
But I want access to my shop like this: http://domain.com.
How can I do this?
If you don't have access to your server configuration.
Add this .htaccess to your / directory.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/Prestashop/.*$
RewriteRule ^(.*)$ /Prestashop/$1 [L]
</IfModule>
Don't forget to change your shop_url in SEO / URL.
You must point your domain name to a specific subfolder.
If you point domain.com on prestashop subfolder then you should change it in your back office:
Preferences -> SEO & URLs
After the change you should disable Friendly URL and then enable it again - Enabling Friendly URL generates .htaccess

Migrating a CodeIgniter site to a different domain and moving the whole thing down one level in directory

I am working on a site, which is built with CodeIgniter.
I have never used the framework before...I've learnt a little bit in the last couple days but really cannot solve my problem.
I have downloaded the site and I want to upload it to my own domain so not to make changes to the live site before testing.
the original site is example.com.
I want to upload it to mysites.com/examplesite (this will be the base - I use this domain for all my clients' test sites).
I have moved all the files and the database is in place.
I have found the database configuration file and have successfully edited it.
I am having trouble getting the site to work, I think it must be because of the site now being down a directory level.
I have edited $config['base_url'] so that it is correct...I am pretty sure it is correct because I can now reach the homepage where I couldn't before editing that variable. But, i can only reach the homepage - when I click on a link to another page, I get 500 error Internal server error.
Does anyone have a quick fix for me?
Thanks!
Keep this code on your project's root .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /examplesite/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

CodeIgniter links not working in localserver

I have a copy of PHP project running using CodeIgniter framework. It's hosted in some server and when I am trying to access a particular URL
www.xxxdomain.com/member/member/index
The above URL is loading a page with CSS
it I call the same link in the below manner still the page is loading but it couldn't load CSS
www.xxxdomain.com/member/index.php/member/index
now, when I download this code and trying to run in my own localserver when I am trying to call as http://localhost/project1/member/member/index I am getting an 404 error at the same time when I call it as http://localhost/project1/member/index.php/member/index the desired page is loading but loading without CSS.
How come the page load with the same URL in my server and not running in my localhost?? I changed the base_url setting and I am pretty high sure that I replaced all instances with the localhost url instead of server url but still the issue persists.
Any idea how to fix this?
create a file .htaccess in your root CI folder in you localserver...
and paste this Rewrite code..
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
if you want to read more about htaccess..
make sure u leave your config index_page blank....$config['index_page'] = "";

Ajax response call, 404 Not Found

i tried to use wordpress and codeigniter for a intelligent join between the best CMS and the best PHP Framework. Actually i intended to use codeigniter for database managemnent and wordpress for display. But i wanted to use codeigniter inside wordpress. So, i have a file tree like that:
www
- codigniter-core folder
- .htaccess
- wordpress-core folder
- .htaccess
- index.php
How can i make the wordpress .htaccess to cover also the codeigniter ant not trowing 404 error in jquery ajax call. My current wordpress .htaccess file it's:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^/codeigniter-core/
RewriteRule ^(.*)$ /index.php/$1 [L]
I also tried to ask this to Wordpress Forums and Codeigniter Forums, but no answer. I think it's hell of a rewrite condition or rule, but i don't know ...
I had this problem when creating a controller file that I would call via the jQuery ajax method. This controller file included wp-blog-header.php.
When you include the wp-blog-header.php in a file outside of WP framework WordPress does a check on the current file, and if it is not in its database it returns a 404. The work around is to add a 200 status header after the wp-blog-header.php.
header("HTTP/1.1 200 OK");
Now (jQuery) ajax to the file returns properly without a 404.
This worked great... can't tell you how long I was looking for this answer. I suspected this had to do with a header error because firebug showed the response but the header had a 404. Thanks this saved me a lot of time.
BTW I used this to fix the Quick Search plugin by Giulio Ganci
Just open the "search.php" file in the plugin folder and add
header("HTTP/1.1 200 OK");
Right after the first line of code. When your done the first few lines of code in this file should look like this
<?php
require('../../../wp-blog-header.php');
header("HTTP/1.1 200 OK");
if (isset($_GET['s']) && trim($_GET['s']) != '') {

Resources