我正在遭受一个Web配置文件,该文件没有重写我的codeigniter应用程序的url。这是web配置文件。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Clean URL" stopProcessing="true">
<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?{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
这是我的网站:
http://gandhitomodi.com
我无法得到这种网址
http://gandhitomodi.com/controller/method/
例如
http://gandhitomodi.com/welcome/index/
请帮我解决这个问题。
****编辑*****
这是route.php
$route['default_controller']="welcome/index";
$route['sendmail']="welcome/send";
这是我已经更改的config.php设置。
$config['base_url']="http://gandhitomodi.com/";
$config['index_page']='';
$config['url_protocal']='PATH_INFO';`
对于您的配置文件, 试试这篇文章。您的问题似乎就在您的行动方面。
<action type="Rewrite" url="index.php?{R:1}" appendQueryString="true" />
改为:
<action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" />
问号导致您的问题。此外,您的匹配行可能会更改为:
<match url="^(.*)$" ignoreCase="false" />
这有点具体,可能会在以后阻止一些令人头疼的问题。
<?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="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?url={R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
你可以试试这个代码它会工作正常我也只使用这个代码
谢谢
当我使用mssql和windows server以及codeigniter平台时,我也遇到了问题。我很难从url中删除index.php,或者你可以说漂亮的网址。经过大量的讨论和研发。我在服务器的根目录下对webcofig文件进行了一些更改。
重写web配置的规则以删除index.php是
:
<configuration>
<appSettings>
// default code..
</appSettings>
<system.webServer>
<handlers>
<clear />
// another default code
</handlers>
<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>
</rules>
</rewrite>
</system.webServer>
</configuration>
肯定它的工作和codeigniter的其余部分工作正常。在routes.php和config.php中设置默认URL等设置也很重要。如果有任何其他帮助写下您的评论。
首先,我们需要从url中删除index.php
所以 route.php 你会改变这条线
$route['default_controller'] = "welcome";
$route['404_override'] = 'notfound';
并在 config.php文件 你会改变这条线
$config['uri_protocol'] = 'AUTO';
之后你需要添加 的.htaccess 文件在网站的根目录中,如下所示:
/application
/system
/assets
/.htaccess
并将此代码添加到 的.htaccess 文件
Header append X-FRAME-OPTIONS "SAMEORIGIN"
Header set Cache-Control "no-store"
Header set X-Content-Type-Options "nosniff"
Header set Strict-Transport-Security "max-age=31536000; includeSubDomains"
ErrorDocument 403 /notfound.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
<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: ollakalla
ErrorDocument 404 /index.php
</IfModule>
然后,您可以像控制器一样访问控制器中的方法
class Reviews extends CI_Controller
{
public function latest()
{
// Some code here
}
}
通过 http://gandhitomodi.com/reviews/latest/