1

具体的には、htaccess を使用して URL を書き換えています... codeigniter を使用しています。「frontend」と呼ばれるアプリケーションと「admincp」と呼ばれるアプリケーションの 2 つがあります。フロントエンド アプリケーションは、$application_folder を「frontend」に変更した index.php を使用します。admincp アプリケーションはコピーされた index.php を使用しますが、名前は admin.php に変更されています。このファイルでは、$application_folder が「admincp」に変更されています。

基本的に、最初の uri セグメントとして「admincp」を含むすべての URI を、index.php ではなく admin.php ファイルに書き換えたいと考えています。次に、他のすべての URL を通常どおりに書き換えます... index.php に。

mysite.com/admin/members は admin.php/members に移動します mysite.com/articles/Some-Awesome-Articles は index.php/articles に移動します

これで十分に説明できたと思います...とにかく、これが私の現在のhtaccessファイルですが、うまくいかないようです。内部サーバー エラーが発生します。

 # 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\.site\.com$ [NC]
    # RewriteRule ^(.*)$ http://site.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 ^admin/(.*)$ admin.php/$1
    RewriteRule ^(.*)$ index.php/$1

</IfModule>

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

4

2 に答える 2

0

RewriteRule説明されているように、キャッチオールルールの前に配置し、最後にで終わるように記述します[L]。残りの処理をスキップし、そのルールを最後として扱います。

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

ドキュメント

于 2012-10-22T06:00:33.437 に答える
0

あなたが持っている最初のルールはadmin.phpそれ自体を書き換えます/index.php/admin.php。また、チェックしてルール!-f!-d のみ適用されるRewriteRule ^admin/(.*)$ admin.php/$12 つの条件。書き換え条件は、書き換えルールの直後の単一にのみ適用されます。したがって、RewriteRule ^(.*)$ index.php/$1ルールには条件がなく、すべての URI をやみくもに書き換えます。また、フラグがないため、書き換えは最後まで続行されます (したがって、以前に行った書き換えはすべて破棄されます)。

ルールを再配置する必要があります。

# rewrite if the request starts with `/admin/`
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin/(.*)$ admin.php/$1 [L]

# not even sure why you need this...
RewriteCond %{REQUEST_FILENAME} !index.php
RewriteCond %{REQUEST_FILENAME} !admin.php
RewriteRule (.*)\.php$ index.php/$1 [L]

# everything else
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
于 2012-10-22T05:58:44.107 に答える