2010-12-29 6 views
0

私は以下のルールを欲しがっていますが、私は正しい設定をしていないようです。スラッシュの有無にかかわらず両方.htaccessで複数のMODを書き直しました

<domain>/training-courses/

最後にそれがに行く必要があります。

:私はそれがこのように振る舞うしたい、この後

<domain>/?index.php?page=training-courses

と各変数余分のために

<domain>/training-courses/success/another-value/and-yet-another/

~

それは無制限の主要変数のためのオプションを持つことができない場合は

<domain>/?index.php?page=training-courses&val1=success&val2=another-value&val3=and-yet-another-value

、私は可変ページ

後少なくとも2つの変数を持っているしたいのですが、これは可能ですか?これをどのように整理するのですか?

私はこれまでのところ、これを持っている:

RewriteEngine On 

RewriteRule ^test/([^/]*)/$ /test/index.php?pagina=$1&val1=$2 
RewriteRule ^test/([^/]*)$ /test/index.php?pagina=$1&val1=$2 

RewriteRule ^test/([^/]*)/([^/]*)/$ /test/index.php?pagina=$1&val1=$2 
RewriteRule ^test/([^/]*)/([^/]*)$ /test/index.php?pagina=$1&val1=$2 

RewriteRule ^test/([^/]*)/([^/]*)/([^/]*)/$ /test/index.php?pagina=$1&val1=$2&val2=$3 
RewriteRule ^test/([^/]*)/([^/]*)/([^/]*)$ /test/index.php?pagina=$1&val1=$2&val2=$3 

答えて

0

私は自分の質問に戻って答えたいと思います。しばらくの間、私は私が望むものを正確に使用しています。

まず第一に、私は私のhtaccessでこれを持っている:

<IfModule mod_rewrite.c> 

    RewriteEngine On 

    # existing folders or files 
    RewriteCond %{REQUEST_FILENAME} -f [OR] 
    RewriteCond %{REQUEST_FILENAME} -d 
    RewriteRule ^.* - [L] 

    # non-existing folders or files 
    RewriteRule ^(.*)/? index.php?p=$1 [L] 

</IfModule> 

これは、すべての回で、実際のファイルにアクセスすることができます。パスが存在しない場合は、パス全体をindex.phpに渡します。

のindex.phpで、私は先頭に次のコードを持っている:

// Split the URL in all its components 
$request = parse_url(strip_tags($_GET['p'])); 
// Only take the path without any leading slashes 
$path = rtrim($request['path'], '/'); 
// Split each variable from eachother 
$path_array = explode("/", $path); 

if(count($path_array)){ 
    // By default I select the first variable as the page I will include later on 
    $page = $path_array[0]; 

    // Each other variable I will pass as $val[#nr] starting with 1. Just to be sure I'm going to strip tags and slashes 
    for($i=1;$i<count($path_array);$i++){ 
     $path_array[$i] = strip_tags($path_array[$i]); 
     $path_array[$i] = stripslashes($path_array[$i]); 
     $val[$i] = $path_array[$i]; 
    } 
} 
else{ 
    // If $path_array doesn't contain multiple variables lets assume $path will contain the $page 
    $page = $path; 
} 

// If $page is empty let's take on the default page to include later on 
if(empty($page)){ 
    $page = "home"; 
} 

if(file_exists($page . ".php")){ 
    include($page . ".php"); 
} 
else{ 
    echo "Page " . $page . ".php does not exist."; 
} 

はあなたにposibilitiesのいくつかの例を与えるために:

domain.com/はhome.php ドメインが含まれます。com/product /にはproduct.phpが含まれます domain.com/product/298833/にproduct.phpが含まれ、$ val [1]として298833が解析されます。 domain.com/product/298833/purple-candleにはproduct.phpが含まれ、298833は$ val [1]と解析されます。 $ val [2]として紫色のろうそく。先頭のスラッシュが含まれていないことに注意してください。どうでもいい。

一般的な改善やヒントがあります。今のところこれは間違いなく私がこの質問をしたときに私が探していた答えです。

0

あなたは、あなたが、mod_rewriteのはそれをサポートしていませんしたい方法でサブフォルダとして無限の変数を扱うことができない、非常に正しいです。

しかし、末尾/オプショナル作るためにあなたの最初の問題への答えで、次のように自分のルールを変更します。それだけでは動作しませんstruggelingの時間と時間後

RewriteRule ^test/([^/]*)/?$ /test/index.php?pagina=$1 

RewriteRule ^test/([^/]*)/([^/]*)/?$ /test/index.php?pagina=$1&val1=$2 

RewriteRule ^test/([^/]*)/([^/]*)/([^/]*)/?$ /test/index.php?pagina=$1&val1=$2&val2=$3 
+0

私は「Internal Server Error」というメッセージが表示されても、末尾のスラッシュに関するヒントはありがたいです – Bob

+0

申し訳ありませんが、投稿する前に簡単なテストを済ませておくべきでしょう。 –

0

を。無制限の変数はサポートされていないので、ページ(pagina)の他に2つの変数があります。 RewriteRulesのが他のrewriterulesからフォルダを除外最初のものから除いて動作し

RewriteEngine On 

RewriteRule ^(test/images|test/css|test/js|test/lib)($|/) - [L] 

RewriteRule ^test/(.*)/(.*)/(.*)/ test/index.php?pagina=$1&e=$2&t=$3 
RewriteRule ^test/(.*)/(.*)/(.*) test/index.php?pagina=$1&e=$2&t=$3 
RewriteRule ^test/(.*)/(.*)/ test/index.php?pagina=$1&e=$2 
RewriteRule ^test/(.*)/(.*) test/index.php?pagina=$1&e=$2 
RewriteRule ^test/(.*)/ test/index.php?pagina=$1 
RewriteRule ^test/(.*) test/index.php?pagina=$1 

なし:私が今持っていることはこれです。実際にはURLをindex.phpにリダイレクトすることになりますが、PHPで値を取得できません。つまり、$ _GET ['pagina']

これは奇妙なことですが、私の好み:

RewriteEngine On 

RewriteRule ^(test/images|test/css|test/js|test/lib)($|/) - [L] 

RewriteRule ^test/(.*)/ test/index.php?pagina=$1 
関連する問題