2011-07-15 9 views
0

新しいウェブサイトでmod_rewriteを使用しています。mod_rewriteエラー

.htaccessファイル

RewriteEngine On 
RewriteCond %{SCRIPT_FILENAME} !-f 
RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?rwr=$1 

index.phpのリンクwww.domain.com/service/webdesign/worksに行くこれにより

if (isset($_REQUEST['rwr'])) { 
    if (substr($_REQUEST['rwr'], -1) == "/") { 
     $modrewrite = substr($_REQUEST['rwr'], 0, -1); 
    } else { 
     $modrewrite = $_REQUEST['rwr']; 
    } 
    $modrewrite = explode("/", $modrewrite); 
} 
if (isset($modrewrite) && $modrewrite[0] != "") { 
    $category = $modrewrite[0]; 
} else { 
    $category = null; 
} 

if (isset($modrewrite[1])) { 
    $service = $modrewrite[1]; 
} else { 
    $service = null; 
} 

if (isset($modrewrite[2])) { 
    $identification = $modrewrite[2]; 
} else { 
    $identification = null; 
} 

を提出 -

$category = "service"; 
$service = "webdesign"; 
$identification = "works"; 

これは動作しますが、私はそれを最適化したい:

.htaccessファイル

RewriteEngine on 
RewriteRule ^(.*)/(.*)/(.*)$ index.php?category=$1&service=$2&identification=$3 

のindex.php

$category = $_GET['category']; 
$service = $_GET['service']; 
$identification = $_GET['identification']; 

ファイルしかし、それは動作しません。どうして?誰でも助けてくれますか?

答えて

0

問題のURLに対してルールが正常に動作するはずです。あなたのApacheの設定やそれを引き起こすような名前のファイルかもしれません。あなたの例のURLは/service/webdesign/worksです。ファイル名がservice.phpであり、何らかの理由でApacheがその書き換えルールを無視する可能性があります。

あなたは、このアプローチを使用することができます。

Options +FollowSymLinks -MultiViews 

RewriteEngine On 
RewriteBase/

# Do not do anything for already existing files 
RewriteCond %{REQUEST_FILENAME} -f [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule .+ - [L] 

# the rewrite rule 
RewriteRule ^([a-z0-9\-_]*)(/([a-z0-9\-_]+))?(/([a-z0-9\-_]+))?$ index.php?category=$1&service=$3&identification=$5 [NC,QSA,L] 

これはテストされ、作業のソリューションです。

+0

hello men何かは、私が/または/ serviceに行くときに私に与えるコードで動作しません。http://localhost/xampp/splash.phpにリダイレクトするだけです。なぜですか? –

+1

なぜそれがあなたのために働かないのか分かりません。それは私のPC上で正常に動作しました - 私はそれが未テストに投稿しません。 Apacheのエラーログを確認してください。何もなければ、あなたのhttpd.confのデバッグ( 'RewriteLogLevel 9')を書き換えて、書き換えログで詳細を確認してください。 – LazyOne