【发布时间】:2013-06-04 17:53:26
【问题描述】:
如果请求的文件或目录不存在,我会尝试将所有请求重定向到脚本,但我需要改进此 .htaccess 以检查文件是否存在于父文件夹中。
我目前有:
RewriteEngine on
# check if requested file or directory exists
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# map requests to contentpage.php and appends it as a query string
RewriteRule ^(.*)/(.*)$ contentpage.php?url=$2&lang=$1
现在,这个 .htaccess 成功重定向
en/products.php -> contentpage.php?url=products.php&lang=en only 如果 products.php 在子目录 /en/ 上不存在(实际上目录 /en/ 并不存在,因此当我有文件时 RewriteCond 无法过滤products.php 在父目录上)。
我需要检查文件是否存在于我的文件所在的顶级目录中。它只需要重定向语言目录,例如 /en /es /de /pt .etc
有人知道如何解决这个问题吗?谢谢
【问题讨论】:
标签: php apache .htaccess parent