.htaccess将目录重定向到单个页面 [英] .htaccess redirect directory to a single page

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

问题描述

我想将所有页面从 .com / blog 目录重定向到 .com / error 目录。

I want to redirect all pages from the .com/blog directory to the .com/error directory.

我已经在网上搜索了,发现了许多不同的操作方式,但我希望它重定向到 页面。

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 / blog / index.nonexisting 重定向到 .com / error / 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 / blog / whatever.php ,它将转到 .com / error / index.php ,如果您访问 .com / blog / random.xml 您将被重定向到 .com / error / 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.

推荐答案

尝试将其放入您的.htaccess文件:

Try putting this in your .htaccess:

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

R 替换为 R = 301 您想要301重定向,并且如果您不希望使用外部重定向,则完全摆脱 R

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.

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

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