3

この質問は Server Fault に適していることは承知していますが、残念ながら、質の低い質問のために禁止されました (私が行った 2 ~ 3 の質問に反対票が投じられました)。

CodeIgniter ルーティングに関連する 2 つの問題があります。

index.php最初の問題は、URLを取り除くことができないように見えることです。削除方法の指示に従いました。WAMP サーバーのルートにある .htaccess ファイル (以下を参照) に次の mod 書き換えコードがあります (CI は独自のフォルダーではなくルートにあります)。httpd.conffileのこの行のコメントを外しましたLoadModule rewrite_module modules/mod_rewrite.so。から削除index.phpしまし$config['index_page'] = "index.php";た。そして、すべての WAMP サービスを再起動しました。

私の2番目の問題は、と呼ばれるコントローラーとsearchと呼ばれるメソッドがあることindexです。http://localhost/index.php/search/index結果の URL を からに変更したいと思いますhttp://localhost/search/whatever_im_searching_for。routes.php ファイルで次のカスタム ルートを試しましたが、うまくいきませんでした。$route['search/(.*)'] = "search/$1";

RewriteEngine On

# Put your installation directory here:
# If your URL is www.example.com/, use /
# If your URL is www.example.com/site_folder/, use /site_folder/

RewriteBase /

# Do not enable rewriting for files or directories that exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# For reuests that are not actual files or directories,
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]

.htaccessCI のカスタム ルーティングの使用方法に関するコードを理解するのに苦労しています。どんな援助でも大歓迎です。前もって感謝します。


編集1

ここに画像の説明を入力

4

4 に答える 4

1

私は同じ問題を抱えていたので、次のように書くだけで修正しました.htaccess

RewriteEngine on

RewriteCond $1 !^(index\.php|images|robots\.txt)

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

そしてそれは完璧に機能しています。

于 2013-11-06T00:26:23.457 に答える
1

2番目の問題:

$route['search/(:any)'] = "search/index/$1";
于 2013-08-25T01:11:53.440 に答える
1

htaccess を次のように編集します。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]

RewriteCond %{REQUEST_URI} ^LoginTut.*
RewriteRule ^(.*)$ index.php?/$1 [L]

RewriteCond $1 !^(index\.php|images|table-images|js|robots\.txt|css|captcha)

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
 ErrorDocument 404 index.php
</IfModule>

検索用語を URL に含めるには、次のようにします。

https://stackoverflow.com/a/12070284/1379394

于 2013-08-23T09:43:19.450 に答える
1

Apache のデフォルト設定ファイルを確認します。WAMPではおそらく

<WAMPSERVER_HOME>\bin\apache\Apache2.2.xx\conf

次のようになっている場合:

    DocumentRoot /var/www
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
    </Directory>

次に両方を変更します。

AllowOverride None

に:

AllowOverride All
于 2013-08-25T10:09:14.207 に答える