我的网站文件夹结构如下所示…
Application Root |- administration |--|- application |--|- system |--|- index.php |--|- web.config | |- application |- system |- index.php |- web.config
这里安装了两个CI
框架。
这里我正在谈论administration
子文件夹。
我的web.config URL Rewrite
如下所示。
<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>
问题是,如果我从site_root/administration/application/config/config.php
$config['index_page']
中删除index.php
,任何控制器函数都显示404页面未find 。 网站根目录web.config
实际上是这样做的。
我想从子目录中的URL中删除index.php
。
1.我怎么能通过web.config
执行它?
2.我怎样才能通过.htaccess
执行它?
我发现了这个 ,但没有回答。
我只是按照Linux系统上的文件夹结构运行模型。
我在codeigniter用户指南中找到了标准的htaccess文件。 所以有两个.htaccess文件。 一个在主应用程序(root)文件夹下,另一个在管理文件夹下。
从两个配置文件中的$ config ['index_file'] =''中删除了index.php。
使用whoami方法创建了一个家庭控制器,这个方法可以回显“管理家庭控制器页面”,管理家庭控制器由/ administration / home / whoami调用,“我是家庭主控制器”我是谁。
两个都返回了相应的消息,表明每个消息都被正确调用。
.htaccess直接出来的用户指南。
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L]
所以我想象同样应该与IIS工作,但不要抱着我。 我发现了一些可能有帮助的。web.config版本的.htaccess
所以对于上面的设置,你应该能够放入合适的URL来击中两个CI实例。
编辑htaccess文件…这将从您的网址中删除index.php。
<Ifmodulee 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] </Ifmodulee>
1)在应用程序根目录下创建一个文件名= .htaccess。 在.htaccess文件中添加下面的代码。
RewriteEngine on RewriteCond $1 !^(index\.php) RewriteRule ^(.*)$ index.php/$1 [L]
2)转到应用程序 – >配置 – > config.php。
replace $config['uri_protocol'] = 'REQUEST_URI';
与这一个
$config['uri_protocol'] = 'AUTO';
你会尝试在CI Index
部分之前添加administration
规则如下:
<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>
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...
我有同样的问题,但现在正在工作。 这是为我工作的。 傅旭的回答很好,但是没有奏效。 因此,如果您对其代码进行了以下修改,那么对您而言可能会像您一样为您工作。
我变了
<rule name="Rewrite Administration Index">
至
<rule name="Rewrite Administration Index" stopProcessing="true">
然后我改变了
<match url="administration/(.*)" />
至
<match url="^administrator/(.*)$" ignoreCase="true"/>
然后
<conditions>
至
<conditions logicalGrouping="MatchAll">
并修改了这一点
<add input="{REQUEST_FILENAME}" pattern="css|js|jpg|jpeg|png|gif|ico|htm|html" negate="true" />
至
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
这是完整的代码:
<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>
我希望这对你有用