0

I downloaded Code Igniter 3.1.7 and am hosting my website on IIS 8. However; I am currently at a stop due to an irritating problem which I have been trying to solve.

My goal is to remove 'index.php' from url when trying to access a controller.

Example: http://localhost/welcome instead of http://localhost/index.php/welcome

Since IIS does not use the htaccess file to create a rule to remove 'index.php' from url. An alternative I tried to do is to use the URL Write add-on provided by IIS.

enter image description here

After I hit Apply. The web.config file is created:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Imported Rule 1" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{R:1}" pattern="^(index\.php|assets|images|js|css|uploads|favicon.png)" ignoreCase="false" negate="true" />
                        <add input="%(REQUEST_FILENAME)" matchType="IsFile" ignoreCase="false" negate="true" />
                        <add input="%(REQUEST_FILENAME)" matchType="IsDirectory" ignoreCase="false" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="./index.php/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

Then I went to application/config/config.php file and changed these variables:

$config['base_url'] = ''; to $config['base_url'] = 'http://localhost/'; $config['index_page'] = 'index.php'; to $config['index_page'] = '';

Afterwards, I try to access using http://localhost/welcome , But I get this message:

404 - File or directory not found. The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.

2

4 Answers 4

1

Try this

in you .htaccess file

RewriteEngine On

RewriteBase /your_subfolder

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?/$1 [L]

in application/config/config.php

$config['index_page'] = '';

update sorry i didn't see that you use IIS 8.0 server

see : https://learn.microsoft.com/en-us/iis/application-frameworks/install-and-configure-php-applications-on-iis/translate-htaccess-content-to-iis-webconfig

Sign up to request clarification or add additional context in comments.

Comments

0

First set your URL Helper here $autoload['helper'] = array(); in application/config/autoload.php

Then set your Base URL here like $config['base_url'] = '' Like this

$config['base_url'] = 'http://localhost/example_project'

OR

$root=(isset($_SERVER['HTTPS']) ? "https://" : "http://").$_SERVER['HTTP_HOST'];
$root.= str_replace(basename($_SERVER['SCRIPT_NAME']), '',  
$_SERVER['SCRIPT_NAME']);
$config['base_url'] = $root; //$root is your codeigniter project name i.e. eCommerce, example_project

Now run your application http://localhost/project-folder-name

Comments

0

Frist time be sure that $config['index_page] = '';

After that try this .htdocs

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

Comments

0
 Index.php remove and HTTP to https redirect in CodeIgniter. make 
 web.conig file and put code.


 <?xml version="1.0" encoding="UTF-8"?>
   <configuration>
      <system.webServer>
          <httpErrors errorMode="Detailed" />
               <asp scriptErrorSentToBrowser="true"/>
               <rewrite>
               <rules>
               <rule name="Rule" stopProcessing="true">
               <match url="^(.*)$" ignoreCase="false" />
               <conditions>
               <add input="{REQUEST_FILENAME}" matchType="IsFile" 
               ignoreCase="false" negate="true" />
               <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
              <add input="{URL}" pattern="^/favicon.ico$" ignoreCase="false" negate="true" />
       </conditions>
      <action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" />
   </rule>
   <!-- redirect non http to https  -->
  <rule name="www redirect" enabled="true" stopProcessing="true">
  <match url=".*" />
  <conditions>
    <add input="{HTTP_HOST}" pattern="^[^\.]+\.[^\.]+$" />
    <add input="{HTTPS}" pattern="off" />
  </conditions>
  <action type="Redirect" url="https://www.{HTTP_HOST}/{R:0}" />
 </rule>
 <rule name="www redirect https" enabled="true" stopProcessing="true">
  <match url=".*" />
  <conditions>
    <add input="{HTTP_HOST}" pattern="^[^\.]+\.[^\.]+$" />
    <add input="{HTTPS}" pattern="on" />
       </conditions>
      <action type="Redirect" url="https://www.{HTTP_HOST}/{R:0}" />
     </rule>
      <!-- redirect non http to https  -->
    </rules>
   </rewrite>
    </system.webServer>

   <system.web>
      <customErrors mode="Off"/>
      <compilation debug="true"/>
   </system.web>

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.