Codeigniter HMVC without 'index.php' - codeigniter

I implemented the wiredesignz HVMC functionality in CI 2.1.7.
The only problem, is that, unlike the tutorial I followed(http://somethingstatic.com/setting-hmvc-codeigniter-2-1/), I have to add 'index.php' in my url:
how it should be according to the tutorial:
http://localhost/site/hmvc
What I actually have to call:
http://localhost/site/index.php/hmvc
How can I configure CI so the 'index.php' is not needed?

You need not to do anything extra. this link will help you to get this thing done. Just normal procedure. I done multiple times with the same one.
Hope this helps you.

//user following code in your .htaccess file to remove index.php from url.
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ ./index.php/$1 [L]

Related

Upload CodeIgniter project to cpanel

I have worked on that the whole day, but I couldn't find why I always get the CI 404 Page not found. The project works very well in localhost. What could be the problem?
This is my .htaccess
RewriteEngine on
RewriteCond $1 !^(index.php|css|js|jq|uploads|robots.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
I suspect the default controller can't be found.
What more do you think I should show you?
I will be grateful for your answers.
PD: I use CI 2.1.2
If you've set up everything right, then try changing your last line to: RewriteRule ^(.*)$ /index.php/?$1 [L]
EDIT
Since it's not working when you disable .htaccess and use index.php, you need to check your config.php for things like base_url, index_page, uri_protocol, etc... and routes.php and make sure the default controller is not capitalized (read more about the naming conventions, but I wrote you the general idea in the comments).

ModRewrite .htaccess / SEO URLs syntax

I am trying to re-use some .htaccess code on a new site/server and it doesn't work correctly. I'm not an expert with URL rewriting so would appreciate it if anyone can see if my syntax is incorrect or if there is something else I need to check server side.
I am using the following code:
Options +FollowSymLinks
RewriteEngine on
# News Pages
RewriteRule ^news/$ /news.php
RewriteRule ^news/(.*?)/$ /news.php?article=$1
It works for the 1st level, /news/ but /news/article-1/ just loads the /news/ (news.php) overview page. /news.php?article=article-1 works correctly.
Server is running Apache 2.2.9 and PHP is in CGI mode.
Try it such way:
RewriteRule ^news/(.*?)/?$ /news.php?article=$1 [L]
RewriteRule ^news/?$ /news.php [L]
[L] in the end of instruction stops server cheacking of other instructions, if current one match.
So you write more specific ahead of more general.
If your rules work correctly being the only one in the .htaccess, then such organisation of them can help.
/? - this means that / at the end can absent or present

Code Igniter URL routing confusion

I have a slight issue. I have configured my default controller as :
c$route['default_controller'] = 'news';
so when I point my browser to http://localhost/mysite all the news get loaded as instructed by the news controller.
Now on this page, I have given links to "read article" to read the full article. For this I have to point my browser to http://localhost/index.php/news/view/news-slug. I want to remove index.php from the url. I had already tried re-routing using wildcard without any success. Can you tell me how to do that?
There is a documentation on removing the index.php from the URL if you are using Apache with it's mod_rewrite:
Removing the index.php file
Using the following rewrite code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Also, there are many similar questions to yours, have a look at these questions from the search:
Search query on removing index.php in Codeigniter
You need to define your .htaccess file for this. Check this wiki: http://codeigniter.com/wiki/mod_rewrite

mod_rewrite understanding sub-directories whilst passing $_GET value server issue?

This may well be a server config issue; or simply a blindly obvious reason I'm missing...
Pre mod_rewrite URL:
www.example.com/subfolder/index.php?userName=x
The devised mod_rewrite:
RewriteEngine on
RewriteRule ^subfolder/[^/]([\w]*)$ /subfolder/index.php?userName=$1 [L]
It is my understanding that the above should allow navigation to: www.example.com/subfolder/x. However this causes a 404 error.
Rewrites without the sub-folder work fine; it is only when adding the subfoler to the mix things fall to put.
Your advice is much appreciated.
Try this one instead (works OK for me):
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/subfolder/index\.php$
RewriteRule ^subfolder/([^/]+)$ /subfolder/index.php?userName=$1 [L]
NOTE:
This rule is to be placed in .htaccess. If placed in server config / virtual host context, some small tweaking will be required.

links in codeigniter

I'm experimenting with codeigniter but don't really understand how links work.
for example, I have a link like this:
localhost/ci/welcome/cat/7
My base url is localhost/ci, so by clicking on this link I would expect the method "cat" of controller "welcome" to be called.
This method is very simple:
function cat()
{
echo "just a test.";
}
Pretty basic - I would expect to see the text on screen, but I just see a 404 -page not found error.
What could be the problem?
http://localhost/ci/index.php/welcome/cat/7
Have you configured mod_rewrite (or URL rewriting in general) properly for CodeIgniter? It's not supported out of the box.
They have some instructions in their wiki.
I had problems with the rewrite rule suggested in the user guide. I was also getting 404s. I had to remove the slash before index.php in the rule.
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
As Veeti says, also remember to enable mod_rewrite for Apache.

Resources