Welcome Guest, Not a member yet? Register   Sign In
getting a not found error
#11

(This post was last modified: 04-10-2019, 01:37 PM by richb201.)

I am having trouble getting .htaccess (or 000-default.conf) to work. I am following the instructions in docs/installation instructions. My root as defined in config.php is $config['base_url'] = 'http://localhost/sub_crud'. I am following these directions:

Removing the index.php file
By default, the index.php file will be included in your URLs:

example.com/index.php/news/article/my_article
If your Apache server has mod_rewrite enabled, you can easily remove this file by using a .htaccess file with some simple rules. Here is an example of such a file, using the “negative” method in which everything is redirected except the specified items:

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

In my case I do have mod rewrite enabled. I also modified .htaccess in the /var/www/html/sub_crud directory to include:

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

But I still get http://localhost/sub_crud/Configure/index which fails because it is missing (correctly) index.php in the URI.

I am stuck. Any ideas?
proof that an old dog can learn new tricks
Reply
#12

Solved. I needed to set config[index]="index.php". On my windows PC and on my aws server I do not need this. Why it is needed on Ubuntu?
proof that an old dog can learn new tricks
Reply
#13

Hi,

My best guess is mod_rewrite is not working properly.
One way to check is to run phpinfo and look at the Loaded Modules in apachehandler if mod_rewrite is listed.
Or look in your /etc/httpd/config/httpd.conf if LoadModule rewrite_module .... is commented.
A good decision is based on knowledge and not on numbers. - Plato

Reply
#14

If you think it is an .htaccess problem you can use this .htaccess file from FuelPHP
that has always worked for me because it covers all environments.

Code:
<IfModule mod_rewrite.c>

    # Multiple Environment config, set this to development, testing or production
    # Set the CodeIgniter Environment.
    SetEnv CI_ENV development
    #SetEnv CI_ENV production

    RewriteEngine on

    # NOTICE: If you get a 404 play with combinations of the following commented out lines
    #AllowOverride All
    RewriteBase /

   # Make sure directory listing is disabled
    Options +FollowSymLinks -Indexes

    # Add Font Types
    AddType application/vnd.ms-fontobject .eot
    AddType font/truetype .ttf
    AddType font/opentype .otf
    AddType font/opentype .woff
    AddType font/opentype .woff2
    AddType image/svg+xml .svg .svgz

    <FilesMatch ".(eot|ttf|otf|woff|woff2|svg|svgz)">
        Header set Access-Control-Allow-Origin "*"
    </FilesMatch>

    Header set Access-Control-Allow-Origin "*"

    RewriteCond $1 !^(index\.php|resources|vendor|assets|css|js|img|images|robots\.txt)

    # Restrict your site to only one domain
    # !important USE ONLY ONE OPTION

    # Option 1: To rewrite "www.domain.com -> domain.com" uncomment the following lines.
    #RewriteCond %{HTTPS} !=on
    #RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    #RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

    # Option 2: To rewrite "domain.com -> www.domain.com" uncomment the following lines.
    #RewriteCond %{HTTPS} !=on
    #RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
    #RewriteCond %{HTTP_HOST} (.+)$ [NC]
    #RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]

    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

    # Remove index.php from URL
    RewriteCond %{HTTP:X-Requested-With}    !^XMLHttpRequest$
    RewriteCond %{THE_REQUEST}                ^[^/]*/index\.php [NC]
    RewriteRule ^index\.php(.*)$            $1 [R=301,NS,L]

   # make HTTP Basic Authentication work on php-fcgi installs
   <IfModule mod_fcgid.c>
       RewriteCond %{HTTP:Authorization} .
       RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
   </IfModule>

    # Send request via index.php if not a real file or directory
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    # deal with php-fcgi first
    <IfModule mod_fcgid.c>
       RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
    </IfModule>

    # no php-fcgi, check for sapi and fpm
    <IfModule !mod_fcgid.c>
        # for PHP5 sapi installations
        <IfModule mod_php5.c>
            RewriteRule ^(.*)$ index.php/$1 [QSA,L]
        </IfModule>

        <IfModule !mod_php5.c>
            # for PHP7 sapi installations
            <IfModule mod_php7.c>
                RewriteRule ^(.*)$ index.php/$1 [QSA,L]
            </IfModule>

            # for fpm installations
            <IfModule !mod_php7.c>
                RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
            </IfModule>
        </IfModule>

    </IfModule>

</IfModule>

Save as .htaccess
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB