0

これは私のURLが現在どのように見えるかです:

http://mysite.com/?page=1

どうすればこれを機能させることができますか?:

http://mysite.com/page/1

同じ質問をする StackOverflow に関する投稿があります。しかし、受け入れられた解決策は私にとってはうまくいきません。私は Codeigniter を使用しており、ページが 404 になるため、おそらく CI サイトの URL パターンが次のようになっているためです。

ドメイン/コントローラー/メソッド

システムは、"page" というコントローラーと "1" というメソッドを要求していると想定していますが、どちらももちろん存在しません。あるいは、私の htaccess ファイル (CI wiki からダウンロードしたもので、index.php を削除し、いくつかのセキュリティ処理を実行します) 内の他のコードとの競合が原因である可能性があります。ここに私の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, '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]

#Pretty urls for pagination links
RewriteRule (.*) index.php?page=$1

</IfModule>

インデントされていないビットは、私にとってはうまくいかない他のSOの質問から得た解決策です。

この CI ページネーションの問題に対する解決策はありますか?


アップデート

わかりました、いくつかのドキュメントを読んでください。今、私はこれを機能させています:

http://mysite.com/home/index/2

それを変換する htaccess ルールは何でしょうか?:

http://mysite.com/page/2
4

2 に答える 2

1

この構成を で行う必要があります/application/config/routes.php(そして、.htaccess既に行っているように index.php を非表示にするだけです)。

$route['page/(:any)'] = 'home/index/$1';

または、@zaherg が思い出したように (数字のみが一致することを保証します):

$route['page/(:num)'] = 'home/index/$1';

このようにして、へのすべてのリクエストがhttp://mysite.com/page/2内部的に処理されhttp://mysite.com/home/index/2ます。

CodeIgniter User Guide - URI RoutingおよびCodeIgniter User Guide - Tutorial - Introductionをご覧になることをお勧めします。

幸運を。

于 2012-04-13T05:12:10.977 に答える
0
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

CodeIgniter ドキュメントから

これで の削除が処理index.phpされますが、その後どうなるかは、CodeIgniter のクエリ文字列の処理がどのように設定されているかによって異なります。パスではなくクエリ文字列を使用するように構成できます。詳細については、リンクを参照してください。

于 2012-04-13T01:21:40.553 に答える