Welcome Guest, Not a member yet? Register   Sign In
Removing index.php in Codeigniter
#1

[eluser]faisal_memon[/eluser]
I am not able to remove index.php from the url's

http://sitename.com/index.php/controller...ethod-name

I don't want index.php in above url.

Explanation of what I want to achieve : Normally we access a view in codeigniter by
Code:
http://site-name/index.php/controller-name/method-name

I don't want to use index.php in any of my urls. I want url's to be like -
Code:
http://site-name/controller-name/method-name

Here is my .htaccess file

Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    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]

    #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>



Please help !!
#2

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums!

I assume you're using site_url()? If that's the case, you need to set $config['index_page'] to an empty string in ./application/config/config.php.

Code:
$config['index_page'] = '';

If that's not the problem, please can you explain what's happening? Are you getting an error? What's not working? What are the symptoms?
#3

[eluser]Bigil Michael[/eluser]
modify .htaccess like this
Code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
#4

[eluser]faisal_memon[/eluser]
Here's what I want to achieve : Normally we access a view in codeigniter by
Code:
http://site-name/index.php/controller-name/method-name

I don't want to use index.php in any of my urls. I want url's to be like -
Code:
http://site-name/controller-name/method-name

@Bigil, Thanks for the reply. I tried your method, but its not working. Can you post the complete .htaccess file

@TheFuzzy0ne, Thanks for the reply. I have already set
Code:
$config['index_page'] = '';
in ./application/config/config.php.

Am I missing anything ?? Guys !!
#5

[eluser]TheFuzzy0ne[/eluser]
I don't understand what you mean. What is the problem exactly? Are you generating your URLs without index.php in them? What happens when you manually type the URL into the address bar? Do you get a 500 error, a 404? Please give us an example of what you're doing, and the result you're getting. We understand what you want to achieve, we just don't understand why it's not working, so we need an actual usage example.
#6

[eluser]TheFuzzy0ne[/eluser]
[Duplicate]
#7

[eluser]faisal_memon[/eluser]
I am able to see the output when i put

Code:
http://site-name/index.php/controller-name/method-name
in the browser. What I want to achieve is. I dont want user to type index.php in address bar within the url. I want to remove index.php completely from the url

I want to see the same output when I type following url(without index.php) in browser.
Code:
http://site-name/controller-name/method-name


Eg : When you type
Code:
www.abc.com/index.php/welcome/hello
in the address bar of the browser you see a Welcome page

I want to see the same welcome page when I type
Code:
www.abc.com/welcome/hello
in the address bar of the browser !!
#8

[eluser]TheFuzzy0ne[/eluser]
I know what you want to achieve. Now if you'd be so kind as to answer the questions I asked previously, I might be able to help you achieve it.

When I asked for an example of what you're doing, I expected your reply to be something like this:

I put this into my address bar: www.example.com/some_controller, and I got a 404 error.

That's much more useful to the people trying to help you than repeating what it is you're trying to do for the third time.

Now - What happens when you type the URL, in the desired format, into your browser's address bar?
#9

[eluser]Edy S[/eluser]
Hi faisal_memon , have you enable mod_rewrite on your apache web server?
It would'nt be work if your apache web server have no mod_rewrite enable.
Create a php file contain this code &lt;?php phpinfo(); ?&gt; the run it, check whether your mod_rewrite have been enable or not.
If it not enable, you may open your apache config file httpd.conf and remove // beside mod_rewrite, restart your web server or your computer then check php info again.
If your mod_rewrite have been enable, it should be work well
#10

[eluser]faisal_memon[/eluser]
@TheFuzzy0ne When I type
Code:
http://site-name/index.php/controller-name/method-name
I see the welcome page

When I type
Code:
http://site-name/controller-name/method-name
, I see 404 Error (Page not found)

I want to see welcome page when I type
Code:
http://site-name/controller-name/method-name



@Edy S mod_rewrite is enabled Sad




Theme © iAndrew 2016 - Forum software by © MyBB