重定向所有页面顶级页面页面、重定向

2023-09-02 20:37:51 作者:要学着在干过的傻事中

我如何重定向一个URL的所有页面,以最顶级的网页?

How can I redirect all pages on a single URL to the most top level page?

例如,如果有人试图进入 http://www.thisdomain.com/sample-子页面他们将被重定向到 http://www.thisdomain.com

For example, if someone tries to enter http://www.thisdomain.com/sample-sub-page they'll be redirected to http://www.thisdomain.com

在讨论的领域有许多关于它的Word preSS装置,所以我宁愿没有单独编辑WP的每个实例。我想有一个小htaccess的片段我可以使用?

The domain in question has a number of Wordpress installations on it so I'd rather not have to edit each instance of WP individually. I assume there's a little htaccess snippet I can use?

我需要能够重定向的所有请求都那些链接到实际页面和那些在错误输入

I need to be able to redirect ALL requests both ones that link to actual pages and those that are entered in error.

推荐答案

的httpd.conf 启用了mod_rewrite和.htaccess,然后把这个code在< $ C C>的.htaccess $ DOCUMENT_ROOT 目录下:

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^sample-sub-page/?$ / [L,R=301,NC]