CodeIgniter Path Issue - .htaccess

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)

Related

CodeIgniter php framework: js and css files inside "application" folder. How to do?

I just installed the php framework CodeIgniter 3 and it seems that JS,CSS and images should be placed OUTSIDE Application folder. If not, link to those files inside views does not run.
For many reasons I would like to have these kind of files inside application/views folder. I think that I should correctly set .htaccess file, but I would also like to "lower my defenses less possible", so give only strict necessary privileges.
How to do it?
Thank you.
Do like this:
RewriteEngine on
RewriteCond $1 !^(index\.php|uploads|assets|js|images|css|robots\.txt)
RewriteRule ^(.*)$ /your_ci_folder/index.php/$1 [L]

.htaccess rewriting - URLs with multi level directories

I have a page deals.php which is placed at root directory that is being accessed by number of internal URLs with multi directory levels. for example this page would be accessed by both following urls.
http://domain/flights/asia/bangkok
http://domain/flights/bangkok
I am using this code in .htaccess to redirect to deals.php
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^flights/asia/([^/]+)/?$ deals.php?country=$1 [NC]
RewriteRule ^flights/([^/]+)/?$ deals.php?country=$1 [NC]
Now the problem here coming is that on deals.php all the images, script and style sheet files are not opening properly. If I try to fix it against one URL by placing ../../ in addresses of all images, script and css, it dont work for other URL.
How to solve this problem? what are the options?
Easy: DO NOT use ../ in links to any resources (images/css/js/etc) -- always use URL that is relative to the WEBSITE ROOT -- that is a "requirement" when you dealing with nice/not-real/rewritten URLs as such URL rarely points to the physical file location.
Lets assume you have a logo that is located at http://www.example.com/images/logo.png.
Now, instead of ../images/logo.png and/or ../../images/logo.png ALWAYS use /images/logo.png.
i think what you want is placing an baseurl in html page, so all the relative path will related to the baseurl, not the current URL in the navigator bar

.htaccess - How to hide the internal directory used by subdomains?

I installed a small FTP space for my classmates which allows them to upload school related documents to my server. After the files have been uploaded, they can be easily accessed via a subdomain i.e. ftp.mydomain.com
Everything is working fine, the files can be downloaded and everything works properly.
There are two things which still annoy me though:
If you enter ftp.mydomain.com you see Index of /my_internal_directory instead of something like Index of /
Once you enter a sub-directory and click the Parent Directory link it will redirect you to ftp.mydomain.com/my_internal_directory/ as well
Is there any way to hide my_internal_directory ?
This is the content of my .htaccess file so far:
RewriteEngine on
RewriteCond %{HTTP_HOST} ftp\.mydomain\.com
RewriteCond %{REQUEST_URI} !^/my_internal_directory/
RewriteRule ^(.*)$ /my_internal_directory/$1 [L]
Any help would be greatly appreciated.
If you are using linux server then you can remove read permission for folder my_internal_directory
If not resolve, try to add:
Options -Indexes
on top of the file.
If still doesnt resolve please post your .htaccess file... :)

htaccess rewriterule for directory is changing the url in a undesireable way

EDIT
After a comment from Seth below, and heading to a helpful apache page here, I have found that VirtualHosts are the way to go for the following issue.
/edit
--ORIGINAL POST--
First, a little background on file setup. I am running a LAMP server that hosts multiple domains. I have staging and live sites on this server, under different directories under the web root.
examples
/webroot/live/site1/[public files]
/webroot/live/site2/[public files]
/webroot/stage/site1/[public files]
/webroot/stage/site2/[public files]
The domains for each of these go to the IP of the server, which points at the webroot directory. I have an .htaccess file there to load the appropriate content based on the http_host.
examples
RewriteCond %{HTTP_HOST} ^www.site1-live.com [NC]
RewriteRule ^(.*)$ /live/site1/$1 [PT,L,QSA]
RewriteCond %{HTTP_HOST} ^www.site1-stage.com [NC]
RewriteRule ^(.*)$ /stage/site1/$1 [PT,L,QSA]
These work great for hitting the home page and any of the internal pages, even with the specific pages being like site1-live.com/view/123. Each site's htaccess handles those.
My issue (sorry it took so long to get here):
When I head to any subdirectory within a site, like www.site1-live.com/rss, the content loads just fine, but the URL changes to something like the following
http://www.site1-live.com/live/site1/rss/
Essentially showing the path from the webroot to the files.
How can I avoid this? I obviously want the url to remain www.site1-live.com/rss. Do I need an htaccess file inside the rss directory to block this somehow?
Thanks in advance!
replace ^www with ^(.*)
then have the whole url in the second line www.yourdomain.com/live/...
Doug,
why do you need the QSA flag?
Anyway, what is happening to you is that mod_index (or whatever is serving you directories) is redirecting you www.site1-live.com/rss (without the ending /) to the equivalent URL with the ending /.
If you don't use mod_alias or something list that on the rewritten URLs, removing the PT should work as you expect.

Use htaccess to mask folder name

Here's a problem I'm always wanting to solve with htaccess. I haven't found a way yet, though it looks like it should be possible - perhaps someone can help.
Let's say I have a folder at the root of my site called /foo/. I want users to be able to access that folder at the path /bar/, but for various reasons I can't rename the folder.
So as not to create confusion I only want one path to ever be seen - that is to say, I don't want people to use the name /foo/ to access the folder; they should always use /bar/. If someone goes to example.com/foo/, their browser should redirect to example.com/bar/ - but the content returned should be the content of /foo/.
To make matters more complicated, pages in /foo/ have dependencies (images, stylesheets, links to other pages, etc) within /foo/ which are hardcoded and can't be changed. These must, of course, still work.
So, to summarise, this is what I want :
Requests for example.com/foo/ should redirect to example.com/bar/.
Requests for example.com/bar/ should return the contents of example.com/foo/.
Is this possible? It looks on the surface as if it would create an infinite redirect... but I'm pretty sure there are ways to prevent that in htaccess, aren't there?
I'd be very grateful for any help.
(PS - for a little extra background: The normal reason I want to do this is to rename the wordpress /wp-admin/ directory to something more professional and easy for customers to remember, such as /admin/. But the same system should work for masking any path in this way.)
I found a sort of workaround - by using a symlink and htaccess in combination.
First I created a symlink from /bar to /foo/.
Then I put this in htaccess :
Options +FollowSymLinks
RewriteRule ^foo/(.*)$ bar/$1 [R,L]
This has exactly the desired result - example.com/bar/ shows the content of the /foo/ directory, and example.com/foo/ redirects to example.com/bar/
But if anyone can come up with a pure htaccess solution I'd much prefer that!
Update :
Ok, I've finally found out how to do this. It turns out to be quite simple...
RewriteCond %{THE_REQUEST} ^GET\ /foo/
RewriteRule ^foo/(.*)$ bar/$1 [R,L]
RewriteRule ^bar/(.*)$ foo/$1
The only problem is that it doesn't take account of RewriteBase, so you have to include the full path in the first line (after ^GET\).
If I understand correctly what you want is something like this inside your .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^foo/$ bar/
RewriteRule ^bar/$ foo/
</IfModule>

Resources