使用 htaccess 删除子目录中的 codeigniter index.php

发布于 2024-11-25 04:42:47 字数 566 浏览 0 评论 0原文

我正在尝试从 CI url 中删除 index.php,但按照说明进行操作后,它似乎不起作用。

我有一个 codeigniter 安装在子目录中运行。路由配置中有一个名为 main 的默认控制器,另一个名为“create”的控制器。默认运行良好,但转到 /create 会返回 324 错误,指出未收到数据。我的 htaccess 看起来像这样:

<IfModule mod_rewrite.c>

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^system.*
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>

I'm trying to remove the index.php from my CI urls, but having followed the instructions it doesn't seem to be working.

I have a codeigniter installation running in a subdirectory. There is a default controller set in the routes config called main, and another controller called 'create'. The default runs fine, but going to /create returns a 324 error saying No Data Received. My htaccess looks like this:

<IfModule mod_rewrite.c>

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^system.*
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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

当梦初醒 2024-12-02 04:42:47

这应该足够了:

<IfModule mod_rewrite.c>
RewriteEngine On

#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
#This last condition enables access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

This should be enough:

<IfModule mod_rewrite.c>
RewriteEngine On

#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
#This last condition enables access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
轻许诺言 2024-12-02 04:42:47

这就是我用的。我的 CodeIgniter 也在子目录中运行。

RewriteEngine on
RewriteCond $1 !^(index\.php|images|swf|uploads|js|css|robots\.txt)
RewriteRule ^(.*)$ /ci/index.php/$1 [L]

This is what I use. My CodeIgniter also runs in a subdir.

RewriteEngine on
RewriteCond $1 !^(index\.php|images|swf|uploads|js|css|robots\.txt)
RewriteRule ^(.*)$ /ci/index.php/$1 [L]
在梵高的星空下 2024-12-02 04:42:47

.htaccess 添加:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

进入 application/config/config.php 并清除索引页配置值:

// Old

$config['index_page'] = "index.php";

// New

$config['index_page'] = "";

解决了我的问题希望其他人也...:)

.htaccess add:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

Go into application/config/config.php and clear the index page config value:

// Old

$config['index_page'] = "index.php";

// New

$config['index_page'] = "";

Solved My problem hope others too... :)

与他有关 2024-12-02 04:42:47

有时你需要启用它的重写模块,运行“apache2启用模块重写”:

sudo a2enmod rewrite

你需要重新启动网络服务器以应用更改:

sudo service apache2 restart

然后按照索菲亚的回答。

Sometimes you need to enable it the rewrite module, run "apache2 enable module rewrite":

sudo a2enmod rewrite

You need to restart the webserver to apply the changes:

sudo service apache2 restart

Then folow Sofia's answer.

萌辣 2024-12-02 04:42:47
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

对于 ubuntu

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

for ubuntu

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文