我想重定向坏的链接,得到404错误。 假设我有以下网址:
http://www.example.com/foobar
如果上面的网址不好,我希望它用.html后缀重定向
http://www.example.com/foobar.html
所以基本上我想确保URL不好而且它不以.html结尾,然后只应用规则,这是与.html后缀相同的URL。
更新:不只是foobar.html
,动态有数千个页面,因此使用/foobar.html
进行重定向不会有效。
以下网址将转到标准404页面
http://www.example.com/this-is-bad.html
在url下面的将转到它的.html页面
http://www.example.com/this-is-bad
urp下面的不会重定向,因为结尾处有斜线
http://www.example.com/foobar/
以下网址正在运行,不应该被重定向到任何地方。这不是文件而是动态页面。
http://www.example.com/this-is-good
由于
答案 0 :(得分:2)
只需使用ErrorDocument 404
:
ErrorDocument 404 /foobar.html
如果您想要完全重定向(更明亮地更改网址),请使用L
ErrorDocument 404 http://www.example.com/foobar.html
此窗台将所有404个网址重定向到/foobar.html
更新:尝试此规则
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^./]+)/?$ /$1.html [L,R=302]