[英]301 Redirect to Incorrect URL
I inherited a live Wordpress website where 30+ pages were 301 redirected to the home page.我继承了一个实时的 Wordpress 网站,其中 30 多个页面被 301 重定向到主页。 Which is... obviously not ideal.
这……显然不理想。
This is an example of what is happening:这是正在发生的事情的一个例子:
https://www.example.com/shop -- 301 --> https://example.com https://www.example.com/shop -- 301 --> https://example.com
In that scenario, this is what I want to be happening:在那种情况下,这就是我想要发生的事情:
https://www.example.com/shop --> https://www.example.com/shop https://www.example.com/shop --> https://www.example.com/shop
I'd consider myself a beginner at Apache.我认为自己是 Apache 的初学者。 I don't typically use htaccess except for basic SSL redirects.
除了基本的 SSL 重定向之外,我通常不使用 htaccess。 I've been banging my head against the wall all night so any advice is welcome.
我整晚都在用头撞墙,所以欢迎任何建议。
EDIT:编辑:
Caching doesn't seem to be the issue as the redirect persists in Chrome incognito.缓存似乎不是问题,因为重定向在 Chrome 隐身模式中仍然存在。 Here's my current .htaccess:
这是我目前的 .htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
UPDATE:更新:
This code in the wp-config file appears to be causing issues. wp-config 文件中的此代码似乎会导致问题。 When I comment it out, some of the URLs are no longer 301 but the page content that is loading is still the home page on every page.
当我将其注释掉时,一些 URL 不再是 301,但正在加载的页面内容仍然是每个页面上的主页。
define('WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST'] . '/');
define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST'] . '/');
Your file looks very similar to the WordPress default, except for a couple items.您的文件看起来与默认的 WordPress 非常相似,除了几个项目。 First, you have multiple
RewriteBase
directives.首先,您有多个
RewriteBase
指令。 The last one wins and controls the entire .htaccess
file.最后一个获胜并控制整个
.htaccess
文件。 This should be corrected.这应该得到纠正。 Second, you have a redirect from
http
protocol to https
, which is probably fine and intentional.其次,您有一个从
http
协议到https
的重定向,这可能是好的和有意的。
According to the WordPress documentation , the default WordPress .htaccess
file contains:根据WordPress 文档,默认的 WordPress
.htaccess
文件包含:
# BEGIN WordPress
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
Working from the WordPress default file above, your file has some added lines that I'll explain.从上面的 WordPress 默认文件开始,您的文件添加了一些我将解释的行。
Ths is a conditional test if the mod_rewrite module is enabled.如果启用了 mod_rewrite 模块,这是一个条件测试。 It's fine, but may be optional in your case.
没关系,但在您的情况下可能是可选的。
<IfModule mod_rewrite.c>
The first two lines below are fine.下面的前两行很好。 The second instance of
RewriteEngine On
should be removed, and may be the source of your issue.应该删除
RewriteEngine On
的第二个实例,这可能是您的问题的根源。
RewriteEngine On RewriteRule.* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteEngine On
These lines check for http
protocol and redirect to https
.这些行检查
http
协议并重定向到https
。
RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This is the end of the conditional block.这是条件块的结尾。 It's fine, and required because you have the line in number 1 above.
这很好,而且是必需的,因为您在上面的第 1 行中有一行。
</IfModule>
Basically, your file looks correct to me, except for the second RewriteEngine On
directive.基本上,您的文件对我来说是正确的,除了第二个
RewriteEngine On
指令。 If you remove that and still have issues, I don't think you have an .htaccess
problem and should look for other issues in WordPress such as redirection plugins.如果您删除它并且仍然有问题,我认为您没有
.htaccess
问题,应该在 WordPress 中寻找其他问题,例如重定向插件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.