2016-04-26 14 views
1

ページが存在しない場合は、.php拡張子を追加します(ただしURLバーで非表示にします)。ダブル.htaccessのルール

3.ページが存在せず、.php拡張子が存在しない場合、単一のページ(query.php)を開き、URLバーに入力した内容を追加します可変パラメータとして(URLバーで打つ)。

例ファイル構造:

のindex.php
pricing.php
query.php

例試験:

[domain]/pricing.php -> [domain]/pricing (showing the pricing.php page) 
[domain]/pricing  -> [domain]/pricing (showing the pricing.php page) 
[domain]/somethingelse -> [domain]/somethingelse (showing the query.php page with ?somethingelse appended) 

htaccessの

RewriteEngine on 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-l 
RewriteRule ^(.*)$ $1.php 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-l 
RewriteRule ^(.*)$ query.php?$1 [L] 

実際のテスト:

グッド

[domain]/pricing.php -> [domain]/pricing (showing the pricing.php page) 
[domain]/pricing  -> [domain]/pricing (showing the pricing.php page) 

悪い

[domain]/somethingelse -> [domain]/somethingelse (showing the query.php page with ?somethingelse_php appended) 

私は上記の持っている.htaccessファイルには、私は$ _GET変数を吐き出すときにそれをquery.phpにリダイレクトする場合、それ以外はしたいすべてが「_php」を示してい添付。私は以前のルールのために推測しています...

+0

ロケットの回答エルは良いです。他のルールの一番上に置く: #index.phpに再ルーティングする RewriteCond%{REQUEST_URI} ^/$ RewriteRule ^(。*)$/index.php [L] – jasondeegan

答えて

0

代わりに以下を試してください。これらの条件/ルールセットは、指定した要件に固有のもので、ユーザーに提供される内容をきめ細かく制御できます。ダンプにつながるはずです/testingを要求する最後のルールの面では

RewriteEngine On 

# Serve the requested file if it exists 
RewriteCond %{REQUEST_FILENAME} -f 
RewriteRule^- [L] 

# If not, then check if its .php equivalent exists 
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule (.+)/?$ $1.php [L] 

# Otherwise, send the request off to query.php 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule (.*)/?$ /query.php?$1 [L] 

、存在しない query.php /testing.php場合に var_sump($_GET)を使用する場合は、以下の

array(1) { ["testing"]=> string(0) "" } 
+0

ありがとうございます - これは私の要求に基づいて正しいので正しいとマークされています。私は[ドメイン] /クエリページの代わりにインデックスページを表示することを確認するためにそれを求めていない...私はその部分を把握します。 – jasondeegan

0

を次のコードを試してみてください

RewriteEngine On 
RewriteBase/
ErrorDocument 404 http://path/to/query.php 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-l 
関連する問題