我正在尝试编写一些 mod_rewrite 规则。目前一切正常。目前我的通用 URL 如下所示:
http://website.com/about-us
http://website.com/privacy
目前,这两个链接被 mod_rewritten to content.php
,因为about-us
并且privacy
不作为 .php 文件存在,而是它们的内容存储在 content.php 检索的数据库中。
我有另一个网址:
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]
如果您需要任何进一步的信息,请告诉我!我很感激回复:)