Welcome Guest, Not a member yet? Register   Sign In
RESOLVED - anchor() not returning expected URI - possible index.php removal issue
#1

[eluser]batty[/eluser]
New to this, apologies in advance.

I am trying to make the CI video tutorial #2 - create a blog - work properly. Am using CI 1.2.7 with XAMPP on a Mac. I have enabled mode_rewrite and added an .htaccess file from the CI site.

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]

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

Where the base_url is (I tried 'localhost/' and other ideas as well):
Code:
$config['base_url'] = "index.php";

Here is the issue: Using this:

Code:
&lt;?=anchor('blog/comments/'.$row->id, 'Comments');?&gt;

Returns this html:

Code:
<a href="index.php/blog/comments/1">Comments</a>

Which when the link on the page hovered over with my mouse is really:

Code:
http://localhost/blog/index.php/blog/comments/1

Finally, this URL will actually display the destination I want:

Code:
http://localhost/blog/index.php/blog/comments/1

So my question is, why have I not successfully removed index.php from the URI? I *think* the .htaccess file is properly set (I put garbage text in the file and received an error).

UPDATE - changing the base_url does not seem to help.

I am stumped.

Thanks in advance for any assistance.
#2

[eluser]umefarooq[/eluser]
hi your base_url should be you site url

Code:
$config['base_url']    = "http://localhost/yoursite/";

remove index.php from the following config param

$config['index_page'] = "";
#3

[eluser]batty[/eluser]
Thanks umefarooq.

I made your suggested changes and indeed the index.php is not required to show localhost/blog. However to get to the destination page I still have to type:
Code:
http://localhost/blog/index.php/blog/comments/1
Removing "index.php/blog/" will not allow the page to be displayed.

Any ideas?
#4

[eluser]umefarooq[/eluser]
use the following htaccess code in htaccess file to remove index.php from links
Code:
# Deny OR Allow Folder Indexes.
# Since we disable access to PHP files you
# can leave this on without worries.
# OR better yet, create a .htaccess file in
# the dir you want to allow browsing and
# set it to +Indexes
Options -Indexes

Options +FollowSymLinks

# Set the default file for indexes
DirectoryIndex index.php

<IfModule mod_rewrite.c>
    # mod_rewrite rules
    RewriteEngine on

    # The RewriteBase of the system (if you are using this sytem in a sub-folder).
    # RewriteBase /site_folder/
    
    # This will make the site only accessible without the "www."
    # (which will keep the subdomain-sensive config file happy)
    # If you want the site to be accessed WITH the "www."
    # comment-out the following two lines.
    # RewriteCond %{HTTP_HOST} ^www\.site\.com$ [NC]
    # RewriteRule ^(.*)$ http://site.com/$1 [L,R=301]
    
    # If a controler can't be found - then issue a 404 error from PHP
    # Error messages (via the "error" plugin)
    # ErrorDocument 403 /index.php/403/
    # ErrorDocument 404 /index.php/404/
    # ErrorDocument 500 /index.php/500/
    
    # Deny any people (or bots) from the following sites: (to stop spam comments)
    # RewriteCond %{HTTP_REFERER} nienschanz\.ru [NC,OR]
    # RewriteCond %{HTTP_REFERER} porn\.com
    # RewriteRule .* - [F]
    # Note: if you are having trouble from a certain URL just
    # add it above to forbide all visitors from that site.

    # You can also uncomment this if you know the IP:
    # Deny from 192.168.1.1
    
    # If the file is NOT the index.php file
    RewriteCond %{REQUEST_FILENAME} !index.php
    # Hide all PHP files so none can be accessed by HTTP
    #RewriteRule (.*)\.php$ index.php/$1
    
    # If the file/dir is NOT real go to index
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    #RewriteCond %{REQUEST_URI} !/admin_asset
    RewriteRule ^(.*)$ index.php/$1 [L]
    
</IfModule>

# If Mod_ewrite is NOT installed go to index.php
<IfModule !mod_rewrite.c>
    ErrorDocument 404 index.php
</IfModule>
#5

[eluser]batty[/eluser]
Thank you.

Now on to my SQL issues. Smile




Theme © iAndrew 2016 - Forum software by © MyBB