2014-10-08 163 views
0

好的,模糊的問題標題,我知道。不知道如何總結這一行。我的CodeIgniter安裝中有兩個應用程序:前端和管理員。每個設置爲正確的應用程序文件夾都有兩個前端控制器。目前,我使用index.php/home作爲前端的主頁,admin.php/home作爲管理面板的主頁。如何重寫某個目錄的URL?

我終於開始從前端的URL中刪除index.php。對於管理員cp,我想使用example.com/admin而不是example.com/admin.php。所以我基本上需要重寫任何有管理員的uri作爲admin.php的第一部分。我認爲將RewriteRule ^admin/(.*)$ admin.php/$1添加到我的htaccess中會有所斬獲,但顯然它不會......不完全是。我的管理員cp中的每個頁面都找不到404頁面。我究竟做錯了什麼?

# Deny OR Allow Folder Indexes. 
# Since we disable access to PHP files you 
# can leave this on without worries. 
# OR better yet, create a .htaccess file in 
# the dir you want to allow browsing and 
# set it to +Indexes 
Options -Indexes 

Options +FollowSymLinks 

# Set the default file for indexes 
DirectoryIndex index.php 

<IfModule mod_rewrite.c> 
    # mod_rewrite rules 
    RewriteEngine on 

    # The RewriteBase of the system (if you are using this sytem in a sub-folder). 
    # RewriteBase /CodeIgniter_1.6.3/ 

    # This will make the site only accessible without the "www." 
    # (which will keep the subdomain-sensive config file happy) 
    # If you want the site to be accessed WITH the "www." 
    # comment-out the following two lines. 
    # RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC] 
    # RewriteRule ^(.*)$ http://example.com/$1 [L,R=301] 

    # If a controler can't be found - then issue a 404 error from PHP 
    # Error messages (via the "error" plugin) 
    # ErrorDocument 403 /index.php/403/ 
    # ErrorDocument 404 /index.php/404/ 
    # ErrorDocument 500 /index.php/500/ 

    # Deny any people (or bots) from the following sites: (to stop spam comments) 
    # RewriteCond %{HTTP_REFERER} nienschanz\.ru [NC,OR] 
    # RewriteCond %{HTTP_REFERER} porn\.com 
    # RewriteRule .* - [F] 
    # Note: if you are having trouble from a certain URL just 
    # add it above to forbide all visitors from that site. 

    # You can also uncomment this if you know the IP: 
    # Deny from 192.168.1.1 

    # If the file is NOT the index.php file 
    RewriteCond %{REQUEST_FILENAME} !index.php 
    # Hide all PHP files so none can be accessed by HTTP 
    RewriteRule (.*)\.php$ index.php/$1 

    # If the file/dir is NOT real go to index 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php/$1 [QSA,L] 
    RewriteRule ^admin/(.*)$ admin.php/$1 

</IfModule> 

# If Mod_ewrite is NOT installed go to index.php 
<IfModule !mod_rewrite.c> 
    ErrorDocument 404 index.php 
</IfModule> 
+0

請啓用[RewriteLog(HTTP://httpd.apache .org/docs/2.2/mod/mod_rewrite.html#rewritelog),增加日誌級別,並在重新嘗試後發佈日誌文件。 – ssnobody 2014-10-08 02:26:50

回答

0

你需要你的index.php路由規則之前添加您的規則。這是因爲^(.*)$admin/whatever匹配,所以您的管理規則永遠不會執行。您還應該添加-Multiviews到你的選擇,所以它看起來是這樣的:

Options +FollowSymLinks -Multiviews 

然後右鍵下RewriteEngine On,添加您的規則:

RewriteRule ^admin/(.*)$ admin.php/$1 [L] 
+0

我仍在爲/ admin下的每個頁面發現404未找到錯誤。 – ShoeLace1291 2014-10-09 00:48:50