我想这样显示一个自定义页面,例如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]
答案 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]