簡體   English   中英

從Web根目錄的子目錄中的CodeIgniter URL中刪除index.php

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

我已經嘗試了幾個小時才能實現這一目標!

我將我的codeigniter應用程序放在webroot的子文件夾中,該子文件夾稱為“ Tat”。

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

如果我訪問:127.0.0.1/Tat/-我轉到CodeIgniter應用程序,那很好。

如果我訪問:127.0.0.1/Tat/index.php/register-我轉到我的CI應用程序的注冊頁面(不要在那里找到index.php!)

如果我訪問:127.0.0.1/Tat/register-它帶我到整個服務器的Web根目錄! 我希望這可以帶我到注冊頁面!

我不知道該怎么做!

值得一提的是:*我的基本URL設置為:$ config ['base_url'] ='http://127.0.0.1:5678/Tat'; *設置了我的索引頁:$ config ['index_page'] =''; *我完全控制服務器,它是在Ubuntu Precise 64上運行Apache2的開發服務器。

如果有人可以指出正確的方向或糾正我的.htaccess或告訴我如何修改很棒的Apache設置!

謝謝。

您的站點位於子文件夾中,因此像第4行一樣設置RewriteBase:

RewriteBase /Tat

我終於找到了答案! 我的服務器配置不正確,沒有啟用mod_rewrite。

Ubuntu用戶,請在命令行將其關閉以啟用它:sudo a2enmod rewrite

然后重新啟動Apache。

我正在使用以下.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