I'm getting crazy with a little problem on my simple web app. I made a simple calendar app with PHP, following MVC pattern.
Dirs structure is like:
calendar (root)
-- app/
-- controllers/
-- core/
-- models/
-- views/
init.php
-- public/
-- css/
-- scripts/
-- others dirs...
-- .htaccess
-- index.php
Every request are made like:
/calendar/public/[controller_name]/[controller_method]/[extra_params]
eg: calendar/public/home/all_events: call all_events method of Home class and then display with right view.
In each view.php I made link/button/etc with classic anchor, using href value like:
...
ex. href="booking/room" in order to call the controller for booking and specify what (room).
Everything seems works fine, but only locally.
When I try to put it on server all links don't work, causing a 404 page not found.
I'm trying to put it into an existing website made with Joomla. every request goes to a specific directory called sitename.com/, where there are all Joomla files plus my directory with the app.
There, I can just reach the app home page (default) but every link is not working.
I tried everything, but nothing seems to work.
I think the issue is in Apache configuration (or .htaccess). It die with a 404 page not found error and my index.php is never called.
This is my htaccess:
Options -MultiViews
RewriteEngine on
RewriteBase /sitename.com/calendar/public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
Or maybe I can't link pages with in that way, but how can I call specific controller/method from html?
Related
I have a website (A) in mydomain.com that uses CakePHP, and it's located in /path/to/sites/mywebsiteA.
Now, I'm setting up a new site (B) that will also use CakePHP, and will be located in /path/to/sites/mywebsiteB.
The challenge comes because I want the URL for website B to be mydomain.com/websiteB. This URL should open the index file of Website B. And then, any link of the form mydomain.com/websiteB/* should be processed by website B as well, while any other link for mydomain.com should be processed by website A.
Currently website A has the following code in its root htaccess file (this is for CakePHP to work properly):
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Website B also has that same code in its root htaccess file since it's also a CakePHP file like I mention above.
How would I modify Website B's htaccess file in order to accomplish what I'm trying?
Examples for clarification
- mydomain.com/contact: should call /contact in website A's folder (basically as if there was no special htaccess rule)
- mydomain.com/users/index: same as above (call /users/index)
- mydomain.com/websiteB/campaign: should call /campaign in website B's folder
- mydomain.com/websiteB/campaign/exec: should call /campaign/exec in website B's folder
- mydomain.com/websiteB/users/create: should call /users/create in website B's folder
I am trying to implement a free MVC found on net. My project is stored in http://localhost/project/
The file and folders structure looks like:
/project/
public/ (here I have index.php plus css subfolder, js etc)
controllers/
views/
models/
File index.php (main one) is being kept in public folder.
Now, when I try to access via web: http://localhost/project/employees it works well and it loads employees controller... But when try to access http://localhost/project/employees/methodtest I get File not Found + my CSS files (stored in public/css/main.css) cannot be load and it show path: http://localhost/employees/methodtest/main.css.
I would like to be able to call http://localhost/employees/somemethod/someparams/etc but with my css folders/files still working.
Here is my redirection setup:
RewriteEngine on
RewriteBase /employees/
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
Is above clear enough in order to get some help? - Thanks!
Here is my views directory:
- views/
- home.php
- contact.php
- assets/
- css/
- main.css
config.php: (changing this doesn't seem to do anything)
$config['index_page'] = 'index.php';
routes.php:
$route['default_controller'] = "welcome";
When I request www.example.com/index.php, the default page (i.e. home.php) loads and all of the assets work. However, when I request www.example.com/index.php/welcome or www.example.com/index.php/welcome/index, the page loads but the assets don't work. The same also happens if I try to load the page from a link from the home page.
I have no idea what index.php is for. I want to be able to just request www.example.com/welcome/index which will call the welcome.php controller and call the index method. application/index.php looks pretty important for everything to work, do I haven't deleted it, but I don't really want it. What can I do?
Thanks.
I think you're asking 3 different questions here.
Firstly index.php is the main entry point for your codeigniter app. It's very important as all of your routes will go through the index. The reason you can change it in the config is so you can rename it to something other than index.php if your setup requires it
Secondly, just guessing here but I think your assets are being loaded using a relative path; prefix all of your assets with base_url(); e.g
<?=base_url();?>assets/css/style.css
Thirdly, you'll need a htaccess file to hide the index.php (to give you www.example.com/welcome), or the equivalent if you're not using an apache server, which will look like the below (taken from http://www.codeigniter.com/user_guide/general/urls.html:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Enable mode Rewriting on your server LAMP/WAMP and add a .htaccess file with following code
RewriteEngine on
RewriteCond $1 !^(index.php|resources)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
after doing above process you can use your urls without index.php i.e like www.example.com/welcome/index as well as your assets directory www.example.com/assets
Before all learn How MVC framework will work,
www.example.com/controller/function
If you call www.example.com , then default controller will load. You can change this in config.php
Inside the function you can call view ( your actual html viewable scripts ). follow the user guide from https://ellislab.com/codeigniter/user-guide
by default codeignitor url will be like www.example.com/index.php/controller/function
index.php can be removed using .htaccess
I am new to codeigniter frame work. I have installed CodeIgniter 2.1.4 version. I set up the application and system path in my local wamp server. The front end opens fine.
But when i try to open the admin i.e http://siteurl/CodeIgniter_2.1.4/admin
it shows as 404 not found. In application >> controllers >> admin.php is found (Hope this is for admin panel)
Then why it shows as 404 not found. Shall i made any setup for admin url? Please help me. Thanks
You will need multiple things in place in order to achieve this:
Set the $config['index_page'] to an empty string in application/config/config.php
You will have to rewrite the requests coming in, for example with apache you will need to have rewrite rules like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1/ [L,QSA]
You can put them into a file called .htaccess next to the index.php (your webserver need to be configured to support these kind of files for this to work)
You will have to have a function called index inside your admin.php, inside a class called Admin.
I have looked at several examples of htaccess configs for websites within sub-directories, and tried most of them without 100% success.
My setup is:
using Yii framework
htaccess at public_html/.htaccess
site located inside public_html/mysite directory
index handling all requests located at public_html/mysite/frontend/www/index.php
The status of the URLs:
www.mysite.com works fine [ok]
www.mysite.com/controller/action shows me the homepage [wrong]
www.mysite.com/mysite/frontend/www/controller/action works fine [wrong, the item above should work instead]
My .htaccess at the moment looks like this:
AddHandler application/x-httpd-php53s .php .html
Options +SymLinksIfOwnerMatch
IndexIgnore */*
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !^/mysite/frontend/www
RewriteRule ^(.*)?$ /mysite/frontend/www/index.php [L]
I have tried everything, but I have no idea why www.mysite.com/controller/action won't work :(
Any help would be really appreciated! Thanks!
I found the answer to this similar question to be helpful. Here is how my rewrite rules ended up:
#Forward all non-existent files/directories to Yii
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) subdir/index.php/$1 [QSA,L]
This takes all non-existent files/folders and sends them to the yii script with initial url appended. QSA appends any query string that may be present in the initial url.
You didn't mention if you configured Yii's Url Manager for clean URLs. You need to, otherwise Yii expects the "route" to appear as a GET param named "r". If you didn't, consult this section of the definitive guide
You dont need to edit .htaccess. You just need to move the Yii entry script (index.php) and the default .htaccess up from the subdirectory to the webroot (so that they reside directly under public_html). Once you move index.php and .htaccess to the root directory, all web requests will be routed directly to index.php (rather than to the subdirectory), thus eliminating the /subdirectory part of the url.
After you move the files, you will need to edit index.php to update the references to the yii.php file (under the Yii framework directory) as well as the Yii config file (main.php). Lastly, you will need to move the assets directory to directly the webroot, since by default, Yii expects the assets directory to be located in the same location as the entry script).
That should be all you need to do, but if you need more details, I describe the approach fully here:
http://muhammadatt.tumblr.com/post/83149364519/modifying-a-yii-application-to-run-from-a-subdirectory
I also didn't update the .htaccess file, easier to modify the httpd.conf virtual host for the subdomain and change the DocumentRoot to point to your yii folder.