1

I have some redirects and urls that use the index controller

absolute or relative like this: www.domain/index/contact or just /index/contact

Can I strip out the index part with htaccess so I wil see www.domain/contact

I only want this for the index controller

EDIT

these are my rules that I already have

Options +FollowSymlinks
RewriteEngine On
Options All -Indexes
IndexIgnore *
DirectoryIndex index.php 
RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteCond %{SCRIPT_FILENAME} !-f 
RewriteRule ^(.*)$ index.php/?$1 [L,QSA]

thanks in advance, Rich

4

1 に答える 1

1

mod_rewriteを調べる必要があります。設定したルールに基づいて、アプリケーションのURLを書き換えるための強力なオプションが多数あります。

.htaccess特定のケースでは、次のようなルールがある場合があります。

RewriteRule /contact(.*)$ /index/contact$1 [L,QSA]

上記のルールは/contact、呼び出し元が/index/controller代わりにアクセスしたかのように、パスへのすべての要求を書き換えます。また、追加のパス情報がキャプチャさ$1れ、置き換えに置き換えられます。このQSAフラグは、リライトエンジンにクエリstrignをそのまま渡すように指示します。

で始まるパスを除いて、すべてのリクエストをルーティングする場合は/static、次のようなルールを使用することをお勧めします。

RewriteCond %{REQUEST_FILENAME} !^/static
RewriteRule ^(.*)$ index/$1 [L,QSA]

これにより、で始まるすべてのURLが無視され/static、それ以外はすべてコントローラーを通過します。

更新しました

行は必要ありませんRewriteCond...実際のファイルとディレクトリのルール処理を特にスキップしたい場合を除きます。また、書き換えパスに構文上の問題があるようです。非常に基本的な書き換え設定から始めて、必要に応じてそこから拡張します。

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !/index\.php
RewriteRule ^(.*)$ index.php/$1 [L,QSA]  # use ? or / but not both

これにより/contact、サーバーが/index.php/contact代わりにアクセスしたかのように動作しながら、ブラウザでアクセスできるようになります。また、ファイルがコードに含まれる場合に備えて、ファイルへの直接のリクエストもすべて無視index.phpされます。

于 2012-11-20T16:29:16.117 に答える