0

I have hosted codeigniter application in apache2.4 with php7.2 docker environment. Not able to resolve routes correctly.

PATH

/var/www/html/apps/sample1

browser PATH

http://localhost:8080/apps/sample1/

working fine but routes controller and actions is not get resolved until i use index.php

http://localhost:8080/apps/sample1/index.php/admin/logn

Correct Expectation

http://localhost:8080/apps/sample1/admin/logn

.htaccess current configuration, Apache mod_rewrite already enabled

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /app/innovative_travel_web/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [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>  
<IfModule mod_php5.c>
  php_value short_open_tag 1
  php_value upload_max_filesize 20M
  php_value post_max_size 20M
  php_value max_execution_time 200
  php_value max_input_time 200
</IfModule>

Kindly please guide me, how can i fix it.

5
  • have you check your apache rewrite mode is on? Commented Nov 1, 2018 at 20:04
  • Yes Apache mod_rewrite is already enabled Commented Nov 1, 2018 at 20:18
  • Reading their documentation is usually an excellent start. Can you please explain why their rewrite directives did not work for you? Commented Nov 1, 2018 at 20:28
  • this might be helpful to you, check it @SyedRaza stackoverflow.com/questions/19183311/… Commented Nov 1, 2018 at 21:54
  • in config file remove index.php in index_page variable. Commented Nov 2, 2018 at 5:31

3 Answers 3

0

1) create htaccess like

RewriteEngine on
RewriteCond $1 !^(index\.php|asset)
RewriteRule ^(.*)$ index.php?/$1 [L]
Options -Indexes

2) in application/config/config.php file

$config['index_page'] = '';
Sign up to request clarification or add additional context in comments.

Comments

0

Set in config.php

$config['index_page'] = '';

Then your .htaccess You RewriteBase might look like below based on your root folder or just / if the app runs in root folder

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /folder_name/

    RewriteCond $1 !^(index\.php|images|robots\.txt)

    #Removes access to the system folder by users.  
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php/$1 [L]

    #This snippet prevents user access to the application folder
    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>
    ErrorDocument 404 /index.php
</IfModule>

Comments

0

Set in config.php

$config['index_page'] = '';

in .hta

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /apps/sample1/index.php/$1 [L]
</IfModule>

U need to specify the directory too since your path is /var/www/html/apps/sample1 not /var/www/html/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.