我想在我的网站上创建一个默认的404页面,我知道如何做到这一点:
ErrorDocument 404 http://example.com/404.html
但我如何从网址创建一个特殊的重定向到此页面:" http://example.com/page-not-found" ??我在谷歌和这里搜索过,但我一无所获。
最后,当用户访问页面:http://example.com/test-page并且我的网站上不存在此网址时,脚本应该将用户重定向到页面:" http://example.com/page-not-found"此URL应显示404.html文件中的html代码。
感谢。
答案 0 :(得分:1)
在根目录中尝试这样,
RewriteEngine on
RewriteBase /my_catalog/
# rewritten rule
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html [L]
# not found rule
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ Page-not-found [R=301,L]
Page-not-found
是你所谓的错误html文件,如果传入的请求也不是文件既不是服务器中的目录,也不会发送内部重写为page-not-found.html
的页面未找到。
答案 1 :(得分:0)
这可以通过
ErrorDocument 404 http://example.com/page-notfound.html
和mod_rewrite完成。
修改:
.htaccess
然后在
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
添加:
%start with :- go.
is_spicy :-
write('Do you want spicy? (yes/no)'),
read(Preference),
( Preference == yes -> recommend("Curry"); recommend("Kurma") ).
is_fry :-
write('Do you want fry food? (yes/no)'),
read(Preference),
( Preference == yes -> recommend("StirFry"); recommend("Chicken") ).
is_chili :-
write('Do you want chili? (yes/no)'),
read(Preference),
( Preference == yes -> recommend("Sambal"); recommend("Singgang") ).
recommend(Food) :- write('We recommend you '), write(Food).
go :-
write('Which food type do you prefer? (indian, chinese, malay): '),
read(FoodType),
(
FoodType == indian -> is_spicy;
FoodType == chinese -> is_fry;
FoodType == malay -> is_chili;
writeln('Please try again')
).
这当然是假设您已启用mod_rewrite。