301将子页面重定向到新主页

时间:2019-03-14 14:13:09

标签: .htaccess redirect

嗨,我是重定向的新手。

我可以使用基本的重定向301 / page1 / https://example.com/newpage/重定向来正常工作。

我在删除父页面及其所有子页面并将所有内容重定向到新的父页面时遇到问题。

主要重定向有效:

Redirect 301 /eye-can-hear/ htps://example.com/procedures-services/

但是尝试重定向子页面

Redirect 301 /eye-can-hear/hearing-services/ https://example.com/procedures-services/

正在重定向到不存在的/ procedures-services / hearing-services/。

.htaccess文件如下所示,2-7不能正确重定向:

Redirect 301 /eye-can-hear/ https://example.com/procedures-services/
Redirect 301 /eye-can-hear/hearing-services/ https://example.com/procedures-services
Redirect 301 /eye-can-hear/hearing-aids/ https://example.com/procedures-services
Redirect 301 /eye-can-hear/self-test-your-hearing/ https://example.com/procedures-services/
Redirect 301 /eye-can-hear/schedule-your-hearing-evaluation/ https://example.com/procedures-services/
Redirect 301 /eye-can-hear/financing/ https://example.com/procedures-services/
Redirect 301 /eye-can-hear/dual-sensory-wellness/ https://example.com/procedures-services/
Redirect 301 /about-costello-eye-physicians/community-involvement/ https://example.com/about-costello-eye-physicians/in-the-news/

还有更多重定向,但我只能发布7个链接。在一些iThemes安全措施之后,.htaccess文件更进一步的是:

# Stop wordpress username enumeration vulnerability
RewriteCond %{REQUEST_URI}  ^/$
RewriteCond %{QUERY_STRING} ^/?author=([0-9]*)
RewriteRule ^(.*)$ https://example.com/? [L,R=301]

还有这个:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

3 个答案:

答案 0 :(得分:0)

更改以下未正确重定向到此重写的行(2-7):

RewriteEngine On
RewriteRule ^eye-can-hear\/(.*)$ https://example.com/procedures-services [R=301,L]

它将/ eye-can-hear / *的所有子页面重定向到https://example.com/procedures-services

答案 1 :(得分:0)

这行代码在 .htaccess 文件中对我有用:

RedirectMatch 301 /eye-can-hear/(.*) https://example.com/procedures-services

它将页面 https://example.com/eye-can-hear/ 及其子页面重定向到 URL https://example.com/procedures-services

答案 2 :(得分:0)

(两年后回答,但也许对某人有帮助)

在 htaccess 文件中,您应该将此重定向放在所有其他子页面重定向之后:

Redirect 301 /eye-can-hear/ https://example.com/procedures-services/

你的 htaccess 应该是这样的:

Redirect 301 /eye-can-hear/hearing-services/ https://example.com/procedures-services
Redirect 301 /eye-can-hear/hearing-aids/ https://example.com/procedures-services
Redirect 301 /eye-can-hear/self-test-your-hearing/ https://example.com/procedures-services/
Redirect 301 /eye-can-hear/schedule-your-hearing-evaluation/ https://example.com/procedures-services/
Redirect 301 /eye-can-hear/financing/ https://example.com/procedures-services/
Redirect 301 /eye-can-hear/dual-sensory-wellness/ https://example.com/procedures-services/
Redirect 301 /eye-can-hear/ https://example.com/procedures-services/