0

私は作品というエイリアスでMAMPを使用しています。コードイグナイターはlocalhost/works/project/web

コントローラーは、その前に index.php がないと機能しません ( localhost/works/project/web/index.php/auth/register)

$config['base_url'] = 'localhost/works/project/web/'; //with http://

$config['index_page'] = '';

$config['uri_protocol'] = 'AUTO'; 

(uri_protocol ですべて試しました)

/User/me/works/project/web/ で .htaccess ファイルを作成および編集しました。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Users/me/works/project/web

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

#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
#This last condition enables access to the images and css folders, and the robots.txt file
#Submitted by Michael Radlmaier (mradlmaier)
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
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.
# Submitted by: ElliotHaughin

ErrorDocument 404 /index.php
</IfModule>

次のようなエラーが発生します。 [error] [client ::1] File does not exist: /Users/me/works/project/web/auth

RewriteBase / を使用する場合も同じです

mod_rewrite は phpInfo でアクティブです。

解決策が見つかりませんでした。

4

8 に答える 8

3

あなたRewriteBaseは間違っています。サーバーの相対ファイル パスではなく、書き換えルールなどの相対 URL パスにする必要があります。詳細はこちら。

HTML の<base>タグを使用したことがある場合、それはほとんど同じ原理です。メインの localhost URL がhttp://localhostで、プロジェクトがサブフォルダーhttp://localhost/my-projectにある場合は、RewriteBase /my-project/.

RewriteBase を使用せず、プロジェクトがサブフォルダーにある場合は、すべての URL にサブフォルダーを追加して、次のように書き換える必要があります。

RewriteRule ^(.*)$ /my-project/index.php/$1 [L]

思考の糧:

  • .htaccess ファイルはできるだけシンプルに作成してください。すぐに実行すればするほど、問題が発生する可能性が高くなり、デバッグが難しくなります。特に .htaccess ファイルに慣れていない場合。やみくもにコピー アンド ペーストしないでください。実際に何が行われるかを理解してください。

  • システム フォルダー アクセス部分は冗長になりました。システム フォルダーには、アプリケーション フォルダーと同様に、要求を制限するための独自の .htaccess があります。

于 2013-03-15T01:25:04.090 に答える
1

1.application/config.php ファイルに以下の変更を加えます

$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].'/Your Ci folder_name';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

2. .htaccess ファイルでこれを使用します。

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

以下のコマンドを使用して書き換えモードを有効にします

 a2enmod rewrite

ファイル /etc/apache2/sites-enabled/000-default を編集します

change the AllowOverride None to AllowOverride All.

そして最後にサーバーを再起動します

于 2013-02-27T05:04:32.780 に答える
0

http://11.12.34.45/~project/のような URL で codeigniter をインストールしました。

私はさまざまな提案を試みましたが、最終的にこの次のURLが解決策を提供しました:

https://ellislab.com/expressionengine/user-guide/urls/remove_index.php.html

于 2015-03-02T12:34:13.923 に答える
0

.htacces を使用する代わりに問題を修正し、それらを httpd.conf に書き込みました。AllowOverride が All であることを確認しましたが、.htaccess が機能しない理由がわかりません。この問題で時間を失いすぎたので、この方法を使用します。答えてくれてありがとう。

于 2013-02-27T09:52:56.210 に答える
0

仮想ホストでAllowOverride Allを使用します。

<Directory "/path/to/your/site">
    ....
    AllowOverride All
</Directory>
于 2013-11-15T03:33:57.750 に答える
0

確かに mod_rewrite がオンになっていないか、MAMP でインストールしていません。

httpd 設定ファイルを開き、変更します

# AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None

AllowOverride All

この行のコメントを外します:

#LoadModule rewrite_module libexec/apache2/mod_rewrite.so 

また、ここでユーザーにいくつかの変更を加えます: /etc/apache2/users/username.conf

LoadModule php5_module        libexec/apache2/libphp5.so

DocumentRoot "/Users/username/where/ever/you/like"

<Directory "/Users/username/where/ever/you/like">
    Options Indexes MultiViews +FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

詳細はこちらhttp://adam.merrifield.ca/2010/08/09/apache-mod_rewrite-php-and-os-x-10-6-snow-leopard/


MAMPを再起動


mod_rewrite がオンになっているかどうかを確認するには、Stackoverflow の次の回答に従ってください。

PHPでmod_rewriteが有効になっているかどうかを確認するには?


.htaccess が問題ではないことを確認するために、これを試していただけますか。テスト済み:

<IfModule mod_rewrite.c>

    RewriteEngine on
    RewriteBase /Users/me/works/project/web/

    # If the start of the URL doesn't match one of these...
    RewriteCond $1 !^(index\.php|robots\.txt|assets|cache|themes|uploads|css|images|js)

    # Route through index.php
    RewriteRule ^(.*)$ index.php/$1 [L]

</IfModule>

特定のフォルダーへのアクセスは上記で許可されており、rewritebase には末尾のスラッシュがあります。


これをオーバーライドする他のネストされた .htaccess があることを確認してください。

于 2013-02-26T16:35:45.693 に答える
0

httpd 設定ファイル LoadModule rewrite_module modules/mod_rewrite.so を開き、 AllowOverride All

          <Directory "C:/xampp/htdocs"> //example for xampp
               Options Indexes FollowSymLinks Includes ExecCGI
               AllowOverride All
               Order allow,deny
               Allow from all
           </Directory>
于 2013-12-24T17:16:38.323 に答える