2012-01-15 27 views
1

私はこの質問が何度も尋ねられていると推測していますが、おそらく私が必要とするものを私に与えることができませんでした。.htaccess RewriteRule trouble

..だから私は、次のURLでスクリプトにアクセスすることができます

http://website.com/index.php/hello/world 
http://website.com/hello/world 

はどちらも(この例では、ハロー/世界)入力を解析しindex.phpのに行きます。しかし

<IfModule mod_rewrite.c> 
Options +FollowSymlinks 

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule (.*) index.php?path=$1&%{QUERY_STRING} [L] 
</IfModule> 

これは私のの.htaccessです。 ?サイトはこのようにアクセスされた場合:

http://website.com/index.php/hello/world 

のRewriteRule出力のindex.phpと似たようなパス= index.phpを/ハロー/世界

私はそのインデックスを削除したいです。 PHPパス= のRewriteRuleで

+0

私はあなたがPHPスクリプトを変換すると思います。 –

+0

@GabrielSantosの問題はありませんhat $ _GET [path]は、/index.php/hello/worldを使用すると存在しません。 –

+0

どういうわけか、私のことと非常に似た質問があります.. http://stackoverflow.com/questions/5123971/apache-htaccess -cut-a-string-from-url-and-redirect –

答えて

1

後にあなたの.htaccessファイルをNotI(次のようになります。 CEのindex.phpをURLの一部であるかどうかを確認する新しいルール):

<IfModule mod_rewrite.c> 
Options +FollowSymlinks 

RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^index.php/(.*)$ index.php?path=$1&%{QUERY_STRING} [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule (.*) index.php?path=$1&%{QUERY_STRING} [L] 

</IfModule> 
+0

あなたは[L]、最後のルールフラグを最初に持っています。なぜそれが動作しないと思うのですか? –

+0

それはありません。 [L]フラグは、クエリが 'index.php?path = $ 1%{QUERY_STRING}' – technology

+0

に既に書き換えられているので、この場合は役に立たない、以下のルールの実行を停止します。ファイルが存在する場合に、ファイルが存在する場合には、RewriteCond%{REQUEST_FILENAME} -fは、ファイルが存在する場合、URLを書き換えるのはどうですか? –

0

この

RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L] 
RewriteRule ^.*$ index.php [NC,L] 
0

この質問

.htaccessを合わせてStackoverflow answerからの回答を変更してみてください。

<IfModule mod_rewrite.c> 
Options +FollowSymlinks 

RewriteEngine On 

# Redirect user 
RewriteCond %{THE_REQUEST} ^.*index.php.* 
RewriteRule ^(.*)index.php(.*)$ $1$2 [NC,R=301,L] 

# Handle the query to PHP 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule (.*) index.php?path=$1&%{QUERY_STRING} [L] 

</IfModule>