2016-12-18 5 views
1

私はより良いURLのために.htaccessを使用しています。私が正常にページ/トリートメント/ライン/ the_id_of_the_pageを入力することができます.htaccessを使用した書き換えの問題

#rewrite treatments-line 
RewriteRule ^/?treatments/line/([0-9]+)$ treatments-line.php?id=$1 [NC,L] 

治療-line.php

私はこのPHPのページを持っています。

しかし、私がpage treatments.phpを作成すると、治療行の書き換えがうまくいかず、単にフロントページが表示されます。テストのために

私はこれに書き換え方法を変更します。

#rewrite treatments-line 
RewriteRule ^/?treatment/line/([0-9]+)$ treatments-line.php?id=$1 [NC,L] 

私は、(「s」はなし)治療に正常に動作しますthe_id_of_the_page /治療/ライン/上の書き換えを名前を変更しましたしかし、私は名前を変更したくありません。

したがって、treat.phpファイルのため、名前と競合していることがわかります。

どうすれば修正できますか?

これらの2つのPHPページは、Webサイトのルートディレクトリにあります。

EDIT2:

ここに私の全体の.htaccessコードだ:

Options -MultiViews 
RewriteEngine on 

#remove .php 
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^([^\.]+)$ $1.php [NC,L] 

RewriteCond %{REQUEST_URL} /(.*)$ 
RewriteRule ^(.*)$ %1.php [NC,L] 

#redirect posts-view 
RewriteRule ^/?post/([0-9]+)$ posts-view.php?id=$1 [NC,L] 

#rewrite products-zone 
RewriteRule ^/?products/zone/([0-9]+)$ products-zone.php?id=$1 [NC,L] 

#rewrite products-category 
RewriteRule ^/?products/category/([0-9]+)$ products-category.php?id=$1 [NC,L] 

#rewrite products-solution 
RewriteRule ^/?products/solution/([0-9]+)$ products-solution.php?id=$1 [NC,L] 

#rewrite products-line 
RewriteRule ^/?products/line/([0-9]+)$ products-line.php?id=$1 [NC,L] 

#rewrite treatments-line 
RewriteRule ^/?treatments/line/([0-9]+)$ treatments-line.php?id=$1 [NC,L]  

#rewrite treatments-category 
RewriteRule ^/?treatments/category/([0-9]+)$ treatments-category.php?id=$1 [NC,L] 

#rewrite product-view 
RewriteRule ^/?products/([0-9]+)$ product-view.php?id=$1 [NC,L] 

#redirect lang 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

RewriteRule ^(.+?)/(.*)$ $2.php?lang=$1 [L] 

#RewriteRule ^([^\.]+)/?$ index.php?lang=$1 [L] 
+0

:だから、これはあなたの.htaccessコードは次のようであるべき方法ですか? – Perumal

+0

いいえ、これらの2つのページの内容は異なります。私は、urlパターンtreat-line.phpを書き直したいだけです。 – user2519032

+0

うん。 'treating.php'のためです。 – Perumal

答えて

2
Options -MultiViews 
RewriteEngine On 
RewriteRule ^/?treatments/line/([0-9]+)$ treatments-line.php?id=$1 [NC,L] 

Options -MultiViewsを追加するには、あなたの問題を解決します。

Options -MultiViewsの詳細については

A MultiViews探索は、Multiviews Optionsディレクティブにより有効になります。 サーバーが/ some/dir/fooと/ some/dir/fooの要求を受けていない場合は、 foo。*という名前のすべてのファイルを探してディレクトリを読み取り、すべて ファイルに名前を付け、同じメディアタイプとコンテンツエンコーディングを割り当てます(クライアントが名前のいずれかを要求した場合は )。それから がクライアントの要件に最も適したものを選択し、 というドキュメントを返します。あなたの.htaccessコードともコメントに基づい

http://httpd.apache.org/docs/2.2/en/mod/mod_negotiation.html#multiviews

、あなたはhtaccessファイルの非常に最後まで#remove .phpルールの位置を変更する必要があります。あなたは `トリートメント-line.php`と` treatments.php`と呼ばれる2つのファイルを持っていて、両方に同じ書き換えURLパターンを持つようにしたい

Options -MultiViews 
RewriteEngine on 

#redirect posts-view 
RewriteRule ^/?post/([0-9]+)$ posts-view.php?id=$1 [NC,L] 

#rewrite products-zone 
RewriteRule ^/?products/zone/([0-9]+)$ products-zone.php?id=$1 [NC,L] 

#rewrite products-category 
RewriteRule ^/?products/category/([0-9]+)$ products-category.php?id=$1 [NC,L] 

#rewrite products-solution 
RewriteRule ^/?products/solution/([0-9]+)$ products-solution.php?id=$1 [NC,L] 

#rewrite products-line 
RewriteRule ^/?products/line/([0-9]+)$ products-line.php?id=$1 [NC,L] 

#rewrite treatments-line 
RewriteRule ^/?treatments/line/([0-9]+)$ treatments-line.php?id=$1 [NC,L]  

#rewrite treatments-category 
RewriteRule ^/?treatments/category/([0-9]+)$ treatments-category.php?id=$1 [NC,L] 

#rewrite product-view 
RewriteRule ^/?products/([0-9]+)$ product-view.php?id=$1 [NC,L] 

#redirect lang 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

RewriteRule ^(.+?)/(.*)$ $2.php?lang=$1 [L] 

#RewriteRule ^([^\.]+)/?$ index.php?lang=$1 [L] 

#remove .php 
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^([^\.]+)$ $1.php [NC,L] 
+0

私は 'Options -MultiViews'を追加しましたが、それでもキャッシュがクリアされても動作しませんブラウザ。 treat.phpの名前をtreat.phpに変更すると、書き換えが機能します。 – user2519032

+0

私は最初に同じ問題がありました。私は 'http:// localhost/treatments/line/2'のようなURLを渡そうとしました。最初は 'http:// localhost/treatments/line/1'でした。これは、キャッシュをクリアして新しいタブを開いて同じURLを渡しても機能しませんでした。最後に、URLの番号を2に変更しました。私はそのような問題を生み出しているものが何であるか分かりません。キャッシュをクリアしたり、ブラウザ全体を閉じると、問題が解決する可能性があります。 – Perumal

+0

私はそれも違う数字で試しましたが、まだ運がありません。 – user2519032