いくつかの mod_rewrite ルールを作成しようとしています。現時点ではすべてが正常に機能しています。現在、私の一般的な URL は次のようになっています。
http://website.com/about-us
http://website.com/privacy
現時点では、これら 2 つのリンクは に mod_rewrite されていますcontent.php
。なぜならabout-us
、 とprivacy
は .php ファイルとして存在せず、コンテンツは content.php が取得するデータベースに保存されているからです。
私は別のURLを持っています:
http://website.com/contact-us
カスタムデータが含まれているため、これは .php ファイルとして存在します。存在するかどうかを確認するにはどうすればよいですかcontact-us.php
。ある場合は にリダイレクトwebsite.com/contact-us
しwebsite.com/contact-us.php
、そうでない場合は にリダイレクトしますwebsite.com/content.php
以下は私の mod_rewrite ファイルです。
RewriteEngine On
# I want the following condition and rule to look to see if the .php file exists,
# and if it does, redirect to the physical page, otherwise, redirect to content.php
RewriteCond %{DOCUMENT_ROOT}/([a-zA-Z0-9\-_]+).php -f
RewriteRule ^([a-zA-Z0-9\-_]+)\.php$ [L]
RewriteRule ^([a-zA-Z0-9\-_]+)$ /content.php [L]
RewriteRule ^(product1|product2|product3)/(designer1|designer2|designer3)$ /search.php?productType=$1&designer=$2 [L]
RewriteRule ^sale/(product1|product2|product3)$ /search.php?sale=1&productType=$1 [L]
さらに情報が必要な場合は、お知らせください。返信ありがとうございます:)