显示未发现文件夹的自定义页面

时间:2015-03-17 08:46:27

标签: .htaccess

我想这样显示一个自定义页面,例如sub.php,无论何时找不到网址

例如

http://domain.com/blabla/
http://domain.com/blabla/bladas.html
http://domain.com/tedabad/dasd/sadsad/

以上是未找到网址的所有示例,我想显示http://domain.com/sub.php的内容,我尝试了下面的代码,但它无法正常工作

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/?$ /sub.php [L]
RewriteRule ^([^/]+)/(.+?)/?$ /$1/sub.php [L]

1 个答案:

答案 0 :(得分:0)

您可以检查sub.php中是否存在RewriteCond并使用ErrorDocument指令:

Options +FollowSymLinks -MultiViews
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1/sub\.php -f [NC]
RewriteRule ^([^/]+)/(.+?)/?$ /$1/sub.php [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /sub.php [L]