Codeigniter: Routes only visible when entering /index segments - codeigniter

I'm working on my first project with codeigniter 2.0 and have a bit of a problem.
On my localhost (a MAMP installation) everything works fine with the routes. Only when i add a copy on my domain, change the base url and other necessary settings like my database settings it works fine for like 99%. I can't access my other controllers directly without adding the /index route. For example when i want to visit the http://my_domain.com/work it'll open the 404 error page but when i enter ttp://my_domain.com/work/index it works fine. Does someone know a setting i have to change for the online version? The Htaccess files are identical.
CHeers in advance.

I found my solution. I just checked the routes.php file in my config where i added a route for every controller. I just removed these and only my default_controller route is left. Now it works fine. Just a codeigniter newbie issue.
Thanks anyways for the help #Hibiscus and #BigFatBaby

I sorted my problem by setting the following line as my .htaccess file.
RewriteEngine On
RewriteRule ^.*$ index.php [NC,L]
It'll rewrite anything after the /index.php/blaha to /blaha.

Related

laravel 5 removing public from url not working on WAMP

Many people post that following htaccess works for removing "public" from url. But i am working on WAMP and this is not working:
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
This shows following Error message from Laravel framework:
Sorry, the page you are looking for could not be found. 1/1 NotFoundHttpException in RouteCollection.php line 161:
There are other methods to remove "public" from url but I want to understand why this method is not working on my side which people followed frequently in their posts. my url is : http://localhost/laravel/ (directory: d:/wamp/www/laravel)
Can any one help me to understand why this popular method is not working on my side? Is their any issue in Laravel internal routing as I think my htaccess is working properly?
Thanks a lot in Advance.
I am sorry this is not exactly what you wanted but... Instead of rewriting the path, go to your Apache config and change your directory so it includes /public as well. That way you will get rid of the now necessary public from the URL. I know it is not an answer to your question, so please do not downvote. Nevertheless, it should solve your problem.
Your router is not picking up the redirected path because your laravel installation is a subdirectory within your webserver and the RewriteRule ^(.*)$ is picking up the whole path which includes /laravel. This is being appended to public/ because it's captured in $1.
The simplest case for you may be to alter the RewriteRule to not capture the laravel directory.
eg:
ReqriteRule ^laravel/(.*)$ public/$1 [L]
You may or may not need a forward slash ^/laravel/(.*)$ ...
Alternatively, (and more correctly) you should setup a virtual host within your apache configuration to serve the laravel application in the root of a virtual host (as it's designed) or you might be better off in the long run using Laravel Homestead as a preconfigured development environment.

Code igniter - 404 not found, routes issue, ssh server

So first off, I am pretty familiar with codeigniter I've used it for multiple occasions. Right now I have a project too do for school and I installed codeigniter on the server but I am getting routing issues I believe.
So additional info about the server which is different from the normal environment I work with, the server uses SSH and it is very weirdly protected in my opinion. You also need a username and password to view the URL in the first place. (I think it's weird)
If this helps the url is:
https://clipper.encs.concordia.ca/~pyc353_2/
and credentials are (username: pyc353_2, password: FMaqRb)
Now I am able to see any page that I set as my 'default_controller' in the routes, but the problem is trying to go to any other page. Right now I'm trying to access the register controller and I just get 404'd (while it works if I set it as default)
I will link all the code I think may be relevant to the error, hopefully it's not server settings since I have no control over any change.
config.php
$config['base_url'] = 'https://clipper.encs.concordia.ca/~pyc353_2/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
routes.php
$route['default_controller'] = "test";
.htaccess (there may be better code for doing this but I used it in the past no problem and the route doesn't work even if I remove htaccess and add back index.php to 'index_page')
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
</IfModule>
So I tried accessing my pagedifferent variations in the url such as: (stackoverflow won't let me post more than 2 physical links)
clipper.encs.concordia.ca/~pyc353_2/register
clipper.encs.concordia.ca/~pyc353_2/index.php/register
neither work although with /index.php/ the error message is: "No input file specified."
So I hope my explanations are clear enough, it's hard to explain something I don't understand the source problem. If you need any additional info feel free to ask. I really need to solve this to proceed at all for my project.
EDIT
I don't know if this is relevant but the 404 message is not even in the codeigniter style it just looks like a plain web 404
Also I am looking at the path on the server and this is the hierarchy: /www/groups/p/py_comp353_2 I don't know if that could affect anything also?
NEWER EDIT
Following what I found here: http://ellislab.com/codeigniter/user-guide/installation/troubleshooting.html
Changing index.php to index.php? (and removing htaccess) actually did make the routing work. Now I am happy enough with this and I can continue working, but being that it's an ugly solve would anyone know how to keep the routing working AND remove the index.php? from my URI?
It appears that your htaccess is not working.
To confirm, create a new PHP file and write this line:
echo phpinfo();
On that page try to search for "mod_rewrite", if it is enabled, you will see it under "Loaded Modules"
It is probable, it is not enabled.
Try this on your server:
a2enmod enable
Then restart the apache server.
For restarting on debian, this should work:
service apache2 restart
For CentOS, this should work:
apachectl restart
That always does not solve the problem.
Even then, try your CI installation in the normal mode after that. (With everything in normal mode: htaccess as before, and no index.php in the URL)
If it does not work, you may need to alter the apache config file httpd.conf
Try to search for this line:
#LoadModule rewrite_module modules/mod_rewrite.so
Uncomment it by removing the # sign
Restart Apache Server.
Test it now, again.
There could still be other things that you could do to enable mod_rewrite.

URL working in local but not in production

I am developing website in magento. I tested it in local and it works fine.
Then i pushed my code into production but it's not working up in there.
It shows me "cms-index-noroute-". I wanted to debug So I deleted copy from my local and copied all the files using ftp from production. But still it works into my local but not working into production server.
Don't know what the problem.
Let me know if you can think of any reason why it's not working..
Any Help would appreciated.
It seems like you are getting 404 error. Did you got the 404 error on all page except the home page ..?If yes, please try to load your page like http://yoursiteurl.com/index.php/anypage.html .Try to add index.php like above I mentioned. Now your page load correctly then, you need to modify your .htaccess file in your root directory. open your .htaccess file and search for the following RewriteBase . Modify your RewriteBase like this.
RewriteBase /yoursitename/ or RewriteBase /

Code igniter and wamp not finding files in different folder

I happened to run into this problem with a code igniter based folder/site in my wamp's www folder, the folder is named igniter and the site works great on that folder, but when I copy paste that folder or simply rename it, the routing stops working.
To be more specific, I enter the newly renamed folder/site via browser, like http://localhost/igniter2 for example, and the code igniter routes to the default/homepage intended but when I try to access any other page via links or direct routing all I get is a 404 page not found error, even if I try to click the homepage link in the homepage it gets the same error.
I tried to look everyone but didn't find answer, can someone help me figure out the problem?
I checked the file www/igniter2/.htaccess and on the first 3 lines i saw:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /igniter/
and changed to:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /igniter2/
Now works wonders :) thanks curious_coder for the tip.
Change the 'base_url' parameter to 'http://localhost/<new_folder_name>/' in config.php.
config.php is present in 'application/config/' folder.
In your case:
$config['base_url'] = 'http://localhost/igniter2/';

How do i do a mod_rewrite in xampp localhost in a sub directory?

I'm a complete newbie to htaccess and I'm having a problem getting the mod_rewrite to work.
I'm trying to change the below:
http://localhost/login/sitepage.php?linklabel=editted
to
http://localhost/login/sitepage/editted
I've looked at loads of solutions online and none of them work. I've used phpinfo() and mod_rewrite is loaded and I've been able to direct the users to a 404.php file with the htaccess file.
any help would be great thanks**
hey guys sorry for the bother there wasn't actually a problem it was just me being really dumb. I misunderstood what mod_rewrite actually did in that i thought it rewrote the url in the bar when you clicked on a link that displays the query in the url bar.
For anyone who has came across the same problem here's the problem and solution:
i wanted this /sitepage.php?linklabel=editted to change to /editted.html
anyway using the code generator at http://www.generateit.net/mod-rewrite/ , in the .htaccess file i put the follwing code -
RewriteEngine On
RewriteRule ^([^/]*).html$ /sitepage.php?linklabel=$1 [L]
When i clicked the button it still went to /sitepage.php?linklabel=editted
I forgot to change editted page
to
editted page because it displays the content from the /sitepage.php?linklabel=editted page in the new url.

Resources