从 URL 中删除 index.php - Codeigniter 2

发布于 2024-10-19 21:16:23 字数 1164 浏览 2 评论 0原文

我在从 Codeigniter 中的 URL 中删除 index.php 时遇到问题。我用 Codeigniter 1.7 制作了一些网站,而我使用的 .htaccess 代码在 2 中不起作用。

我尝试过使用

<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>
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ ./index.php/$1 [L]

</IfModule>

在没有 RewriteBase / 的情况下也尝试过。

我更改了 $config['uri_protocol' ] 到 REQUEST_URI 和 QUERY_STRING,什么也没有。

我已经设置了 $config['index_page'] = "";

文件结构是192.168.0.130/(site)/,所以它一定是回到服务器的根目录,找不到index.php文件。

我制作的所有控制器都可以通过输入 192.168.0.130/(site)/index.php/testcontroller 来访问,

谢谢。

如果之前有人问过这个问题,我深表歉意 - 我已经查看并尝试了我能看到的内容。

编辑:

我还应该补充一点,我将默认文件夹更改为

应用程序

CI-2.0

index.php

并将 index.php 中的路径更改为正确的。

I am having trouble removing index.php from my URLs in Codeigniter. I've made a few websites with Codeigniter 1.7 and the .htaccess code I used doesn't work in 2.

I have tried using

<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>

and

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ ./index.php/$1 [L]

</IfModule>

I've also tried it without RewriteBase / in.

I have changed the $config['uri_protocol'] to REQUEST_URI and QUERY_STRING and nothing.

I have set $config['index_page'] = "";

The file structure is 192.168.0.130/(site)/ so it must be going back to the root of the server and can't find the index.php file.

All of the controllers I have made can be reached by putting 192.168.0.130/(site)/index.php/testcontroller

Thank you.

Apologies if this has been asked before - I have looked and tried what I could see.

Edit:

I should also add that I changed the default folders to be

application

CI-2.0

index.php

and changed the paths in index.php to be correct.

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

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

发布评论

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

评论(7

楠木可依 2024-10-26 21:16:23

尝试您发布的第一个代码块,但尝试使用 /(site)/index.php 代替 /index.php (obv 将 (site) 替换为您的站点文件夹的名称)。

Try the first code block you posted, but instead of /index.php try using /(site)/index.php (obv replacing (site) with whatever your site folder is named).

仙气飘飘 2024-10-26 21:16:23

这对我有用:

  1. 创建 htaccess 文件
  2. 将 $config['index_page'] 设置为空(config.php)
  3. 字符串 Set $config['uri_protocol'] = 'REQUEST_URI'; (config.php)

这是我的 htaccess 文件:

Options -Indexes
Options +FollowSymLinks

RewriteEngine On
RewriteBase /

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]

#When your application folder isn't in the system folder

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

# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin   

ErrorDocument 404 /index.php

来源:

http://taggedzi.com/articles/display/codeigniter -2-htaccess-and-friend-urls

This worked for me:

  1. Create your htaccess file
  2. Set $config[‘index_page’] to an empty (config.php)
  3. string Set $config['uri_protocol'] = 'REQUEST_URI'; (config.php)

This is my htaccess file:

Options -Indexes
Options +FollowSymLinks

RewriteEngine On
RewriteBase /

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]

#When your application folder isn't in the system folder

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

# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin   

ErrorDocument 404 /index.php

Source:

http://taggedzi.com/articles/display/codeigniter-2-htaccess-and-friendly-urls

淡笑忘祈一世凡恋 2024-10-26 21:16:23

我为此呆了两天..尝试了一切可能的方法。我刚刚发现您需要以下内容:

类型:

sudo nano /etc/apache2/sites-available/default

并将AllowOverride None更改为AllowOverride All - 这将允许访问您的.htaccess文件

<Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
            # Uncomment this directive is you want to see apache2's
            # default start page (in /apache2-default) when you go to /
            #RedirectMatch ^/$ /apache2-default/
</Directory>

并且还可以在Apache上启用mod重写:

http://stackoverflow.com/questions/3131236/how-do-you-enable-mod-rewrite

希望这会有所帮助,
马里奥

I was on this for 2 days.. Tried everything possible. I've just came out that you need the following:

TYPE:

sudo nano /etc/apache2/sites-available/default

And change AllowOverride None to AllowOverride All - This will give access to your .htaccess files

<Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
            # Uncomment this directive is you want to see apache2's
            # default start page (in /apache2-default) when you go to /
            #RedirectMatch ^/$ /apache2-default/
</Directory>

And also enable mod rewrite on Apache:

http://stackoverflow.com/questions/3131236/how-do-you-enable-mod-rewrite

Hope this helps,
Mário

萌吟 2024-10-26 21:16:23
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?/$1 [L]

仅在根文件夹中需要这么多,将其添加到 .htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?/$1 [L]

This much is only required in root folder add this to .htaccess

陌生 2024-10-26 21:16:23

遵循其他人以及此 CodeIgnitor URL 文档 的所有说明后,不要忘记重新启动服务器。我只是忘记这样做并继续尝试所有其他解决方案。

After following all instructions from other people and from this CodeIgnitor URL documnetation, don't forget to restart the server. I simply forgot to do that and kept trying all other solutions.

昵称有卵用 2024-10-26 21:16:23

您只需在 .htacess 中添加以下代码即可。

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

You just need to add below code in .htacess.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
時窥 2024-10-26 21:16:23

1)在根文件夹中创建 .htaccess 文件

 RewriteEngine on
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]

2)在应用程序文件夹中编辑 application/config/config.php 文件

$config['base_url'] = 'http://localhost/projectName';

 $config['index_page'] = '';         // remove index.php 

我希望它对您有用

1) Create .htaccess file in your root folder

 RewriteEngine on
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]

2) Edit application/config/config.php file in Application folder

$config['base_url'] = 'http://localhost/projectName';

 $config['index_page'] = '';         // remove index.php 

i hope it will work for you

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