Installing codeigniter in a subfolder and point to the main site? - .htaccess

I'm trying install my codeigniter application in a sub folder: http://website.com/sub_folder
And I want that this site is accessible through: http://website.com/
I have the following info in my application/config.php file for the base url: $config['base_url'] = 'http://website.com/sub_folder';
This is my .htaccess:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|captcha|assets|favicon\.gif|robots\.txt)
RewriteRule ^(.*)$ /sub_folder/index.php/$1 [L]
The problem is that when I change the $config['base_url'] to access my asset files, like css etc al my other links using $base_url() point to : http://website.com/sub_folder too instead of http://website.com/

If I understand what you want to achieve, you're doing it wrong, simply place index.php file in your root folder and your application to the sub-folder.
Change system and application paths in index.php to where exactly they are located and you're done.
$system_path = 'subfolder/system';
$application_folder = 'subfolder/applications';
In any case, if it's possible, consider moving application and system folders out of the root directory as it will cover hundreds of potential security holes.

Related

Tweak htaccess file to map a folder name to an actual folder

I want to mask the path of a folder using htaccess file.
So on the server I have this real folder called mydata which contains many php files and subfolders.
When I retrieve data from this folder, in php or html files, I want to write the path as somedata, instead of mydata; for example:
/somedata/mydatafile.php instead of /mydata/mydatafile.php.
So the mydata folder name will be always hidden from users for security reasons. somedata is just a name, there isn't an actual folder on the server.
I have a few addon domains beside the main domain, and the same mydata folder exists on each add-on domain too.
The structure in cPanel is:
/public_html/mysite.com/mydata
/mysite2.com/mydata
/mysite3.com/mydata
where mysite.com is the main domain and the others are addons.
The htaccess file should map somedata folder name to mydata folder name, in any path in any domain and addon-domain,
so I would place it in the root (is root considered where public_html, mysite2.com and mysite3.com sites are?)
I prefer to do it without redirect, the simplest way possible for the server.
With RewriteEngine On, I tried the following:
1.
Alias /somedata /mydata
2.
RewriteRule ^mydata/(.*)$ /somedata/$1 [NC,L]
3.
RewriteCond %{REQUEST_URI} ^/somedata
RewriteRule .* /mydata/ [NC,L]
I'm stuck because of the syntax, can we make at least one work...?
Your second try is close, but you have the arguments backwards:
RewriteRule ^somedata/(.*)$ /mydata/$1 [NC,L]

.htaccess url redirect from one an old page to a new one keeping the root directory same

I have an application whose codebase is deployed inside a folder shop . The URL to the main application is http://myapp/shop/.
One of the links on my page reads
http://myapp/shop/website-design/design-urself.php
which I want to redirect to http://myapp/shop/website-design/index.php
The rule which I am using in my .htaccess file is :
RewriteEngine On
RewriteBase /
RewriteRule ^/website-design/design-urself.php /website-design/index.php [R=301]
But the link is wrongly being getting redirected to http://myapp/website-design/index.php
I tried by removing the leading slash (/) from the urls as :
RewriteRule ^website-design/design-urself.php website-design/index.php [R=301]
but still it doesn't work.
I can understand that probably changing the RewriteBase to shop will solve my problem.
However , the thing here is - going further, the folder name ("shop" in my case) can change . So , in that case I have to again go and modify the .htaccess , which is not desirable.
What is the appropriate RewriteRule I should use in this case?
UPDATE : I have my .htaccess file located at my document root , i.e, inside the folder shop and outside of all other folders residing inside shop.

Make subfolder act as root for the site contained in that subfolder

I have tried to find a solution to my problem but I have not been able to find any questions/answers that address this specific issue.
I've been tasked with moving a website that was built under its own domain - www.example.com - to now reside in a subdirectory of another site - www.otherSite.com/example.
The site to be moved was built with many references to $_SERVER['DOCUMENT_ROOT'] as well as many relative URLs that start at the root. For example:
<?php include $_SERVER['DOCUMENT_ROOT'] . '/nav.php'; ?>
and
/images/logo.jpg
The problem, of course, is that all of those references to the root for the site moving to the subdirectory will reference www.otherSite.com thereby breaking all of those URLs.
I'm hoping that there's a some way, possibly using .htaccess in the subdirectory, to set that subdirectory as the root for the site in that subdirectory.
Note - I am on shared hosting and do not have access to httpd.conf.
Thanks very much.
On www.otherSite.com host place this code in DocumentRoot/.htaccess:
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://(www\.)?domain\.com/example/ [NC]
RewriteRule ^((?!example/).*)$ /example/$1 [L,NC,R=301]
Have you tried redirecting to the sub-folder from your cpanel?, have you check if some of the settings were stored in a database for the site if any?
Please add more codes from the site so we can understand how the codes look like.

CodeIgniter Path Issue

I am use Codeigniter to creat my site. it is a huge site with a lot of contents.
i use the default welcome controller for all pages.
the path is like this now
http://mydomain.com/index.php/welcome
and my folder structure is like this
/root
/codeigniter Application folder
/controller
/view
/static/
/images/
/css/
/pdf/
.htaccess
because i am doing the content first, so all the images are set to absolute patch (http://mydomain.com/static/images/foldername/pc.jpg)
now when i use the rewrite to remove "inde.php" and "welcome"
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|system|pdf|sitemap\.xml|profile.htm|^([A-z,0-9,_,-]+).asp|(.*)\.pdf|phpadmin)
RewriteRule ^(.*)$ /index.php/welcome/$1 [L]
all css and image file are not accessible anymore. I have nearly a thousand pages with images. I don't have the time to change the page one by one. the deadline is coming, please help.
thanks
Have you tried adding the css-folder to your excluded rewriteconditions?
RewriteCond $1 !^(index\.php|images|robots\.txt|system|pdf|sitemap\.xml|profile.htm|^([A-z,0-9,_,-]+).asp|(.*)\.pdf|phpadmin)
Does not seem to exclude the folder css from rewriting (see images is excluded).
Try something like
RewriteCond $1 !^(index\.php|images|css|robots\.txt|system|pdf|sitemap\.xml|profile.htm|^([A-z,0-9,_,-]+).asp|(.*)\.pdf|phpadmin)
Good luck
I think the problem lies with your .htaccess file. We have a similar setup, and that url living outside of the application directory is available just as you have it with a direct url relative to its path. Check out the wiki at http://codeigniter.com/wiki/mod_rewrite for the correct way to set up your .htaccess file.
Edit to clarify: The url http://mydomain.com/static/images/foldername/pc.jpg should work. something about your .htaccess file is wrong.
RewriteCond $1 !^(static|index.php|images|robots.txt|system|pdf|sitemap.xml|profile.htm|^([A-z,0-9,_,-]+).asp|(.*).pdf|phpadmin)

htaccess to fix broken links on local site

So after moving a live site onto a local computer for offline show casing, a lot of the links have broken because of missplaced ../ that dreamweaver puts in.
It works online because the user of that domain doesn't have permission to leave it's doc root, but not so locally.
Is there an .htaccess that I could put the root dir that would restrict or redirect back to itself when trying to navigate to it's parent?
So the site is in xampp/mysite/ and an img src has a value of ../images/image.png
So it's looking for the image at xampp/images/image.png instead of staying in it's root dir of xampp/mysite/images/image.png
I am assuming that all of your images are in the /xampp/mysite/images directory.
If so, then you could try adding the following to your .htaccess file in the root directory of your site.
RewriteEngine on
RewriteBase /
#if request is not in xampp/mysite/images/
RewriteCond %{REQUEST_URI} !^/xampp/mysite/images/ [NC]
#rewrite images to /xampp/mysite/images
RewriteRule /(.+\\.(png|jpg|gif))$ /xampp/mysite/images/$1 [NC,L]

Resources