0

I'm trying to run a PHP codeigniter website on Azure.

But when I set

$config['index_page'] = '';

of my config.php it shows me an error saying "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable"

So once I set that to

$config['index_page'] = 'index.php';

I could load my website.

Now in my urls look like this

http://mysamplesite.azurewebsites.net/helloworld/index.php/Demo

But I want that to be like this,

http://mysamplesite.azurewebsites.net/helloworld/Demo

But every time when I remove that index.php part I got the above mentioned error.

I tried to change my htaccess file, but keep getting the error, this is my htaccess file,

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

Also I had to use site_url() instead of base_url.

So how can I drop index.php from the url?

  • 1
    Don't know but I found this answer saying you need a web.config file instead of .htaccess. https://stackoverflow.com/a/33658887/3585500 – ourmandave Nov 17 '17 at 18:55

4 Answers4

0

put this in your .htaccess file. it should works

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#CI_FOLDER is the Location of your CI files.

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

#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
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>
# 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>
samehanwar
  • 3,280
  • 2
  • 23
  • 26
0

create a .htaccess file at your root directory and put this code in it.

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

<Files "index.php">
AcceptPathInfo On
</Files>  

This will work!!!!

Viraj Shah
  • 369
  • 1
  • 4
  • 11
0

As @ourmandave mentioned in the comment above, in Azure App Service, you need a web.config file instead of .htaccess and put the following to it:

<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>

                <rule name="Rewrite to index.php" patternSyntax="Wildcard">
                    <match url="*" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php" />
                </rule>

            </rules>
        </rewrite>
    </system.webServer>
</configuration>
Aaron Chen
  • 9,835
  • 1
  • 16
  • 28
0

Write below code into .htaccess file

DirectoryIndex index.php
RewriteEngine on

RewriteCond $1 !^(index\.php|(.*)\.swf|fonts|images|css|less|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]
Jaimin Vyas
  • 114
  • 5