简体   繁体   English

从Web根目录的子目录中的CodeIgniter URL中删除index.php

[英]Removing index.php from CodeIgniter URL in a sub-directory of the web root

I have been trying for hours to achieve this! 我已经尝试了几个小时才能实现这一目标!

I have my codeigniter application in a subfolder of the webroot, the subfolder is called 'Tat'. 我将我的codeigniter应用程序放在webroot的子文件夹中,该子文件夹称为“ Tat”。

I am using the following .htaccess file in the codeigniter folder (next to the application and system folders): 我在codeigniter文件夹(应用程序和系统文件夹旁边)中使用以下.htaccess文件:

<IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteBase /

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

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Rename 'application' to your applications folder name.
    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]

</IfModule>

<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.
    ErrorDocument 404 /index.php
</IfModule>

If I visit: 127.0.0.1/Tat/ - I go to the CodeIgniter app, that's good. 如果我访问:127.0.0.1/Tat/-我转到CodeIgniter应用程序,那很好。

If I visit: 127.0.0.1/Tat/index.php/register - I go to the register page of my CI app (dont want the index.php there!) 如果我访问:127.0.0.1/Tat/index.php/register-我转到我的CI应用程序的注册页面(不要在那里找到index.php!)

If I visit: 127.0.0.1/Tat/register - it takes me to the web root of the whole server! 如果我访问:127.0.0.1/Tat/register-它带我到整个服务器的Web根目录! I want this to take me to the register page! 我希望这可以带我到注册页面!

I have no idea how to do it! 我不知道该怎么做!

It's worth mentioning that: * My base URL is set: $config['base_url'] = 'http://127.0.0.1:5678/Tat'; 值得一提的是:*我的基本URL设置为:$ config ['base_url'] ='http://127.0.0.1:5678/Tat'; * My index page is set: $config['index_page'] = ''; *设置了我的索引页:$ config ['index_page'] =''; * I have total control over the server, it's a development server running Apache2 on Ubuntu Precise 64. *我完全控制服务器,它是在Ubuntu Precise 64上运行Apache2的开发服务器。

If anyone can point me in the right direction or correct my .htaccess or tell me how to modify the apache settings that would be awesome! 如果有人可以指出正确的方向或纠正我的.htaccess或告诉我如何修改很棒的Apache设置!

Thanks. 谢谢。

您的站点位于子文件夹中,因此像第4行一样设置RewriteBase:

RewriteBase /Tat

I have FINALLY found the answer! 我终于找到了答案! My server wasn't configured correctly, I didn't have mod_rewrite enabled. 我的服务器配置不正确,没有启用mod_rewrite。

Ubuntu users, fire this off on the command line to enable it: sudo a2enmod rewrite Ubuntu用户,请在命令行将其关闭以启用它:sudo a2enmod rewrite

Then restart Apache. 然后重新启动Apache。

I am using the following .htaccess: 我正在使用以下.htaccess:

<IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteBase /

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

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Rename 'application' to your applications folder name.
    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]

</IfModule>

<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.
    ErrorDocument 404 /index.php
</IfModule>

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

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