简体   繁体   English

codeIgniter 的 mod_rewrite

[英]mod_rewrite for codeIgniter

Has anybody in the history of the internet and web development, been able to get rid of the "index.php" with mod_rewrite in codeIgniter.有没有人在互联网和 web 开发的历史上,能够用 codeIgniter 中的 mod_rewrite 摆脱“index.php”。

I've been trying for several days now and nothing seems to work.我已经尝试了几天,似乎没有任何效果。

I'm using this one (in .htaccess file):我正在使用这个(在 .htaccess 文件中):

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule> 

Not sure where I got it but it works for my codeigniter install, local and live.不知道我从哪里得到它,但它适用于我的 codeigniter 安装、本地和现场安装。 Don't forget to set $config['index_page'] = '';不要忘记设置$config['index_page'] = ''; in your config file.在你的配置文件中。

For mod_rewrite use the following in your .htaccess file对于 mod_rewrite,在 .htaccess 文件中使用以下内容

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

If your codeigniter instance is running in a subdirectory then use the rewrite base command before the RewriteRule如果您的 codeigniter 实例在子目录中运行,则在 RewriteRule 之前使用 rewrite base 命令

RewriteBase /subdirectory/

Then set然后设置

$config['index_page'] = '';

In the config file.在配置文件中。

You might have your .htaccess file in the wrong place.您可能将 .htaccess 文件放在错误的位置。 CodeIgniter has a default .htaccess placed in the applications folder, which I mistakenly took for the one I should edit. CodeIgniter 有一个默认的 .htaccess 放置在应用程序文件夹中,我错误地将其作为我应该编辑的文件夹。

You actually need to create a new .htaccess under the root folder.您实际上需要在根文件夹下创建一个新的 .htaccess 。 So not code_igniter/applications/.htacces...but code_igniter/.htaccess所以不是 code_igniter/applications/.htacces...而是 code_igniter/.htaccess

Hope this helps.希望这可以帮助。

I have used the settings provided above and they always worked - unless I did not have mod_rewrite enabled.我已经使用了上面提供的设置并且它们总是有效 - 除非我没有启用 mod_rewrite。

If you are having issues check to ensure you have mod_rewrite enabled.如果您遇到问题,请检查以确保您启用了 mod_rewrite。 If you do not it will not matter what you put into.htacess or your Apache config如果您不这样做,那么您放入.htacess 或您的 Apache 配置将无关紧要

Yes, I configured it under Linux using the instructions from here .是的,我使用此处的说明在 Linux 下配置了它。 However, I configured it via httpd.conf instead of using .htaccess .但是,我通过httpd.conf配置它,而不是使用.htaccess

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM