.htacess重定向目录单页 [英] .htacess redirect directory to a single page

查看:123
本文介绍了.htacess重定向目录单页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要重定向的 .COM /博客所有目录到 .COM /错误目录。

我在网上搜索,发现了做不同的方式加载,但我希望它重定向到一个页。

I have searched the web, and found loads of different ways of doing it, but I want it to redirect to a single page.

所有的我都试过的事情重定向到文件名相同,但在不同的目录中。例如,的.com /博客/ index.nonexisting 重定向到 .COM /故障/ index.nonexisting

All the things I have tried redirect to the same file name, but in different directory. For example, .com/blog/index.nonexisting redirects to .com/error/index.nonexisting.

我想在第一个目录中的所有文件重定向到某个文件,所以如果你去的.com /博客/ whatever.php 那就去< $ C C> .COM /故障/ index.php文件 $,如果你去的.com /博客/ random.xml 你会重定向到 .COM /故障/ index.php文件

I would like all files in the first directory to redirect to a certain file, so if you go to .com/blog/whatever.php it would go to .com/error/index.php, and if you go to .com/blog/random.xml you would be redirected to .com/error/index.php.

有没有办法做到这一点?

Is there any way to do this?

推荐答案

尝试把这个在你的.htaccess:

Try putting this in your .htaccess:

RewriteEngine on
RewriteRule ^blog/(.+) error/index.php [L,R]

替换研究 R = 301 如果你想有一个301重定向,并且摆脱<$ C $的ç>研究全部,如果你不希望外部的重定向。

Replace R with R=301 if you want a 301 redirect, and get rid of R entirely if you don't want an external redirect.

这篇关于.htacess重定向目录单页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆