Codeigniter web.config or .htaccess index.php rewrite inside a subdirectory

The structure of my website is similar to below ...

Application Root |- administration |--|- application |--|- system |--|- index.php |--|- web.config | |- application |- system |- index.php |- web.config 

The CI environment is installed here.

  • site root
  • administration folder

Here I am talking about the administration subfolder.

My web.config URL Rewrite as follows.

 <rules> <rule name="Rewrite to index.php"> <match url="index.php|robots.txt|images|test.php" /> <action type="None" /> </rule> <rule name="Rewrite CI Index"> <match url=".*" /> <conditions> <add input="{REQUEST_FILENAME}" pattern="css|js|jpg|jpeg|png|gif|ico|htm|html" negate="true" /> </conditions> <action type="Rewrite" url="index.php/{R:0}" /> </rule> </rules> 
Problem

is that if I delete index.php from $config['index_page'] from site_root/administration/application/config/config.php , any controller function shows 404 pages not found . The root of the web.config site really does this.

I want to remove index.php from a url inside a subdirectory.

1. How can I execute it through web.config ?

2. How can I execute it through .htaccess ?

I found this , but received no response.

+5
source share
6 answers

I just ran the layout according to your folder structure on Linux system.

I added a standard htaccess file, as you will find in the codeigniter user guide. So there are two .htaccess files. One in the main folder of the application (root), and the other in the administration folder.

Removed index.php from $ config ['index_file'] = '' in both configuration files.

A Home controller was created in both cases using the whoami method, which simply returns the echo "I am the administrator control home page" for the administrator. The home controller called / Administration / home / whoami and "I am the main home controller" for / home / Whoami.

Both returned corresponding messages indicating that each of them was correctly called.

.htaccess directly from the user guide.

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

So, I think the same should work with IIS, but don't keep me that way. I found something that might help there ... version of .htaccess .

So, for the above setup, you must be able to host the appropriate URLs to get into both CI instances.

+1
source

Edit in the htaccess file ... which will remove index.php from your URL.

 <IfModule mod_rewrite.c> RewriteEngine on RewriteBase /projectname RewriteCond $1 !^(index\.php|resources|robots\.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L,QSA] </IfModule> 
0
source

1) create a file name = .htaccess in the root of the application. add the following code to your .htaccess file.

 RewriteEngine on RewriteCond $1 !^(index\.php) RewriteRule ^(.*)$ index.php/$1 [L] 

2) goto application-> config-> config.php.

 replace $config['uri_protocol'] = 'REQUEST_URI'; 

with this

 $config['uri_protocol'] = 'AUTO'; 
0
source

try adding the administration rule to the CI Index section as follows:

  <rule name="Rewrite Administration Index"> <match url="administration/(.*)" /> <conditions> <add input="{REQUEST_FILENAME}" pattern="css|js|jpg|jpeg|png|gif|ico|htm|html" negate="true" /> </conditions> <action type="Rewrite" url="administration/index.php/{R:1}" /> </rule> <rule name="Rewrite CI Index"> <match url=".*" /> <conditions> <add input="{REQUEST_FILENAME}" pattern="css|js|jpg|jpeg|png|gif|ico|htm|html" negate="true" /> </conditions> <action type="Rewrite" url="index.php/{R:0}" /> </rule> 
0
source
  1.Go to **"application/config/config.php"** then Edit $config['index_page'] = "index.php" To $config['index_page'] = "" AND $config['uri_protocol'] ="AUTO" to $config['uri_protocol'] = "REQUEST_URI" 2.Now go to Root directory not Inside */application* then create file with file name .htaccess and paste the bellow code and save the file. RewriteEngine on RewriteCond $1 !^(index\.php|resources|robots\.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L,QSA] 3.Now you have to enable your server rewrite_mode/rewrite_module, so search for it in google For your LAMP/WAMP server... 4.restart your server You nailed it bro, Now everything is done... 
0
source

I had the same problem, but now it works. Here is what worked for me. Fu Xu's answer was good, but it didn’t quite work. So, if you make the following changes to your code, this may work for you, as well as for me.
I changed <rule name="Rewrite Administration Index">
for the image <rule name="Rewrite Administration Index" stopProcessing="true">

then I changed <match url="administration/(.*)" />
for the image <match url="^administrator/(.*)$" ignoreCase="true"/>

then
<conditions>
for the image <conditions logicalGrouping="MatchAll">

and also changed this value <add input="{REQUEST_FILENAME}" pattern="css|js|jpg|jpeg|png|gif|ico|htm|html" negate="true" />
for the image <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />

here is the full code:

 <rule name="Rewrite Administration Index" stopProcessing="true"> <match url="^administration/(.*)$" ignoreCase="true"/> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> </conditions> <action type="Rewrite" url="administration/index.php/{R:1}" /> </rule> <rule name="Rewrite CI Index" stopProcessing="true"> <match url="^(.*)$" ignoreCase="true" /> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> </conditions> <action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" /> </rule> 

Hope this works for you.

0
source

Source: https://habr.com/ru/post/1258094/


All Articles