I'm a new in CodeIgniter.
I made public folder, where I want to put my css/js/images folders.
My setup is like that:
application
cache
config
controllers
public
css
js
images
....
....
....
My .htaccess is:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /moviesmvc/
#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>
how can I make this public folder public?
/////////////////////////
You really don't want to put your public folder inside your application folder. Your directory structure should be like this
-- application
-- system
-- public
-- css
-- js
-- images
-- index.php
-- .htaccess
This is the best practice to follow and you will save yourself a lot of time and potential problems in the future
If it's a Linux server then you need to change the folder permissions to 755 or 777. Have a Google around for this and you will get a lot more detail.
I would recommend not using CI at the minute as it isn't being developed on any more until they find a new owner. Instead, I would recommend Laravel as it's such an amazing framework, but you should also try out CakePHP, Symfony, Yii or something else which is still being developed.
Check Your Public Folder Permission as well as use base_url() function to get the public url..
for example
echo base_url('public/images'); to get image public path
I would not advise to implement this type of design and here is why:
Web servers are designed to not allow public access below the document root. This aides in both ease-of-setup and security.
If a major security change is made within the root then it has to be duplicated to your public folder.
You are adding unnecessary processing to EVERY HTTP/HTTPS call to your web server because now the rules have to be processed for every request. If you could build this into your httpd.conf file instead then the overhead is nearly non-existent.
TL;DR;
No need to re-invent the wheel by adding a lump around the perimeter.
Related
I have this web api project which is developed by other company. The file structure is:
/project
---/app
---/ApiEndpoint.php
---/public
---/index.php
The DocumentRoot is pointing to /project/public. The index.php is working (http://myapi.com/), however when I try to browse into the api endpoint http://myapi.com/api/endpoint I got 404 error.
How do I configure the .htaccess to rewrite this condition?
/project/public/.htaccess config
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*)$ /index.php?path=$1 [NC,L,QSA]
</IfModule>
The current configuration is there to make sure every request go to index.php (that is probably dispatching requests in some way) except for the files that actually are in the public directory (probably needed for static files like images, and such).
If you wrote a php yourself to be directly called by http://myapi.com/api/endpoint, you should put it in /project/app/public/api/endpoint/index.php.
BUT I suspect you should study that application more and understand the current dispatching method, before doing that.
I have read the doc from Yii2 official website to deploy yii2 into share host from this : http://www.yiiframework.com/doc-2.0/guide-tutorial-shared-hosting.html, and about discussion on this : stackoverflow.
So, I decide to use sftp to upload the yii2 folder.
And this is the list of directory in my share host.
access-logs
etc
logs
public_ftp
public_html
ssl
www (this is a link folder to public_html)
You know, because the share host can hold on domains untill 5 domains,
is it possible to upload yii2basic folder into public_html folder ?
So the result like this :
access-logs
etc
logs
public_ftp
public_html
-basic
- bunch of yii folders here
ssl
www (this is a link folder to public_html)
Because now, if I want to access my web, I have to write like this : mydomain.com/basic/public_html/index.php
I need like this :
mydomain.com/index.php
Please guide me.
Yes you can upload it inside the public_html folder but the only problem that I have been facing nowadays with yii2 basic app is the pretty URLs, you can clone or upload entire contents inside the public_html folder, what I did is as follows only the difference is I have a web folder instead of www
directory structure
public_html
assets
commands
config
controller
mail
migrations
models
runtime
tests
vendor
views
web
public_html/.htaccess
<IfModule mod_rewrite.c>
Options +SymLinksIfOwnerMatch
RewriteEngine On
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} ^/.*
RewriteRule ^(.*)$ web/$1 [L]
RewriteCond %{REQUEST_URI} !^/web/
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ web/index.php
</IfModule>
public_html/web/.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
this works but in the URL it shows /web/index.php?r=site/index and as soon as I turn the prettyUrl on in the config file urlManager it would only show default index page and every link I try to open ends up on the home page view although the URL in the address bar is correct and urlManager parses the rules correctly, this is as far as I have gone.
If you don't mind bunch of Yii 2 folders in your root folder just place all basic template folders (except web) and files in the root folder. Then place the content of web folder in the public_html folder.
It should be something like:
access-logs
assets
commands
config
controllers
etc
logs
mail
models
public_ftp
public_html
// here should be the content of web folder of Yii 2 basic app
runtime
ssl
test
views
widgets
I have been seeing several PHP online tutorials where they recommend that you have a public folder where you have your index.php and other views, css, js, etc and another folder (usually called app) where you have your classes and such. The idea is for the site to use the public folder as default so no one will be able to access the classes. The question is, once I upload the public and app folders to my server, how do I get the users to public/index.php when they type in mypage.com (without them having to type mypage.com/public).
You can use this .htaccess file, Place it in root folder of your website:
RewriteEngine on
RewriteCond %{HTTP_HOST} example\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /public/$1 [L]
I have just installed Flexi Auth Plugin on my Linux system by exactly following the Installation Guide
When I navigate to code http://localhost/codeigniter/ It is displaying the fancy demo page. However, when I click on "Demo" Link from top menu, Its displaying page not found error
Not Found
The requested URL /auth_lite/demo was not found on this server.
Apache/2.2.22 (Ubuntu) Server at localhost Port 80
Do I need to configure my routes.php? In the installation guide, It says only to edit the default controller like this $route['default_controller'] = "auth_lite/index";
By the way, I am very new to CodeIgniter. If any one encountered this problem, please help me.
search source-files for 'flexi_cart',
especially in three *library.php files,
there are some string-entries, that have to be
changed to your own directory.
Seems to work with that changes.
It does sound like your .htaccess file is either not working or not set as it should.
The server is looking for the filepath /auth_lite/demo where it should be passing that string to index.php.
Here's one of the most common .htaccess files for CI. Try it and see:
<IfModule mod_rewrite.c>
RewriteEngine On
# developing in a subfolder? (http://localhost/app/) change this to app/
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|images|robots\.txt|css|js|swf|wymeditor|galleries|ffeiliau)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Try it and see.
I am new to codeIgniter and .htaccess stuff.
I already made to remove the index.php to localhost/ci/index.php/site/home.
So my home page can access now to localhost/ci or localhost/ci/site/home.
I have
Home and About
I can access Home and About if I Am on this link localhost/ci/site/home.
But once I'm on localhost/ci the problem exists because when I click to About the site is redirecting me to localhost/ci/about instead of localhost/ci/site/about. I change the links to Home and About the browser keeps adding the /site every click like
localhost/ci/site/site/site/site/site/site/home
Anyone can help me to fix the problem?
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ci
#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
Have you looked at the URL Helper? It has many functions which will help in these situations.
First make sure you load the helper either in your Controller or autoload configuration.
anchor()
The anchor() helper would be ideal in this instance. e.g.
<?php echo anchor('home', 'Home'); ?>
base_url()
Or alternatively you could build up the href using base_url as previously mention.
About
Go to your config file and set index_page to be empty.
This will remove the index.php
and when you write links set / infront as :
Home and About
what #Svetlio said + i advise you to use site_url() when creating links
You're re-adding the main controller even though the htaccess is set to see that as the base. Writing your links as follows should fix the issue.
About
The other way around it is to run off the base at all times, which isn't really necessary but can work if you're having issues otherwise.
About
What that is going to do is echo out whatever you have set as the base URL in your config every time you write a link so if your base_url in your config is www.localhost.com the above will write www.localhost.com/about.
Don't worry you'll get the hang of it, the routing is probably the most complicated part of CI when you first start.
Home
About