我想调用codeigniter控制器类的function就像这样。 但这是行不通的,我想从URL中删除index.PHP
与index.PHP这工作得很好如何从url中删除index.PHP?
XAMPP上的VirtualHost
Mod_Rewrite设置子域和目录为GEtvariables
$ _SERVER 和$ _SERVER 有什么区别?
如何启动停止使用CMD的Tomcat服务器?
我变了
$config['index_page'] = 'index.PHP';
至
$config['index_page'] = '';
但没有奏效
如何将$ _SESSIONvariables传递给websocket服务器?
Apache:如何重写没有文件扩展名的URL并忽略大小写?
如何在Apache上默认启用完美的前向保密?
Apache忽略MIMEtypes
ubuntu服务器上的Apache 2.4.6:客户端被服务器configuration拒绝(PHP FPM)
第一份工作 –
改变了配置文件
$config['index_page'] = 'index.PHP';
至
$config['index_page'] = '';
(你已经完成了)
第二份工作 –
您必须在根目录中添加一个.htaccess文件,并确保您的PHP mod_rewrite已启用。
欲了解更多信息,请参阅RewriteRule文档。
RewriteEngine on RewriteRule ^([a-z0-9_-]+).html$ index.PHP/page/$1 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond $1 !^(index.PHP|asset|robots.txt) RewriteRule ^(.*)$ index.PHP/$1 [L]
试试这个 希望它的作品,让我知道发生了什么事情。
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.PHP/$0 [PT,L]
一个不错的使用.htaccess的例子列表可以在这里找到http://www.askapache.com/htaccess/modrewrite-tips-tricks.html
RewriteEngine on RewriteRule ^([a-z0-9_-]+).html$ index.PHP/page/$1 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond $1 !^(index.PHP|asset|robots.txt) RewriteRule ^(.*)$ index.PHP/$1 [L]
试试这个代码。 谢谢。
如果您使用的是xampp,请在下面的位置创建htaccess文件
“htdocs / codeigniter / .htaccess”
然后把htaccess的内容
$config['index_page']是正确的,但是你还需要做一件事情:
您必须在codeigniter根目录中使用.htaccess文件,将所有对index.PHP文件的调用重写,而不需要在url栏中有index.PHP
我的文件看起来像这样:
<Ifmodulee mod_rewrite.c> RewriteEngine On RewriteBase / ### Canonicalize codeigniter URLs # If your default controller is something other than # "welcome" you should probably change this RewriteRule ^(welcome(/index)?|index(.PHP)?)/?$ / [L,R=301] RewriteRule ^(.*)/index/?$ $1 [L,R=301] # Removes trailing slashes (prevents SEO duplicate content issues) RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)/$ $1 [L,R=301] # Enforce www # If you have subdomains,you can add them to # the list using the "|" (OR) regex operator RewriteCond %{HTTP_HOST} !^(www|subdomain) [NC] RewriteRule ^(.*)$ http://www.YOURSITE.COM/$1 [L,R=301] # Enforce NO www #RewriteCond %{HTTP_HOST} ^www [NC] #RewriteRule ^(.*)$ http://YOURSITE.COM/$1 [L,R=301] ### # 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] # 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] </Ifmodulee> <Ifmodulee !mod_rewrite.c> # Without mod_rewrite,route 404's to the front controller ErrorDocument 404 /index.PHP </Ifmodulee>
这个文件也重写了所有非www的调用(比如YOURSITE.com到www.YOURSITE.com ,你也可以用另一种方式来做),然后你必须评论这个部分(用# ),并且推荐下面的部分。
它也使得网址更好(canocalized网址)。 如果你看看下面的URL:
/category /category/index /category/index/
这是同一个控制器中的相同功能的3个url。 与上面提供的.htaccess ,网址将是
/category
另一个重要的事情要注意:对于使用任何参数的index方法的控制器,这些URL仍然可以这样工作:
/welcome/index/123 /category/index/123
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。