Welcome Guest, Not a member yet? Register   Sign In
Remove index.php from URIs
#1

[eluser]RomanN[/eluser]
Hello all.

As I have read on another forum's topic to remove index.php from URI I need simply modify my .htacceess file. After adding the below code into the file everything seemed to work well.

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]

    #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>
    ErrorDocument 404 /index.php
</IfModule>

But it works correctly only for default controller. When I'm trying to type some other controller with function and some parameter I'm getting "Oops! This link appears to be broken." error.

Can somebody help with it, please.
Thanks!

P.S. May be next info will be helpful. I'm using Snow Leopard as OS, MAMP for working with Apache/PHP/MySQL.
Index page config parameter is empty.
Code:
$config['index_page'] = "";
#2

[eluser]BrianL[/eluser]
"Oops! This link appears to be broken" is DNS error from browsers when typing in wrong domain name.

RewriteRule ^(.*)$ /index.php/$1 [L]
redirect to http://example.com/index.php/$1

RewriteRule ^(.*)$ index.php/$1 [L]
redirect to http://example.comindex.php/$1

Wink
#3

[eluser]RomanN[/eluser]
Thank you, BrianL, for quick response.

I have tried you mode rewrite rule, but without success. The problem is the same as previous.
I'll try to describe it more carefully.

1. http://localhost/site_name/index.php - works well
2. http://localhost/site_name/ - also works correctly.
3. http://localhost/site_name/index.php/con.../parameter - All is ok.
4. http://localhost/site_name/controller_na.../parameter - Doesn't work!

As you can see second url works nice without index.php specified. The third also works. It means that controller, method and parameter are passed correctly.

Can somebody help me with fourth url?

Thanks.
#4

[eluser]RomanN[/eluser]
Thank you all for helping.

Below rule fixed the problem:

Code:
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
#5

[eluser]pickupman[/eluser]
Glad you got it working. It looks your first solution was a problem with RewriteBase /. Since you were in a subfolder it would be rewriting to http://localhost/. The other url's with index.php are requesting index.php file which is why they were working.




Theme © iAndrew 2016 - Forum software by © MyBB