简体   繁体   English

在WordPress中将.htaccess用于https和www到非www

[英].htaccess in Wordpress for https and www to non-www

does anyone have any idea, why my redirection from www to non-www might not work? 有谁知道,为什么我从www重定向到非www可能不起作用?

Basic Info: Strato Hoster, Worpress Domain redirection is working for: bitcoinmesse.com Sub-Domain redirection not working: shop.bitcoinmesse.com 基本信息:Strato Hoster,Worpress域重定向适用于:bitcoinmesse.com子域重定向不起作用:shop.bitcoinmesse.com

Current .htaccess: 当前的.htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
</IfModule>


# 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

Tried so many different things, all through the web. 通过网络尝试了许多不同的事物。 Most of them lead to this: 他们大多数导致:

Internal Server Error 内部服务器错误

The server encountered an internal error or misconfiguration and was unable to complete your request. 服务器遇到内部错误或配置错误,无法完成您的请求。

Others just said I have an infinite loop: 其他人只是说我有一个无限循环:

Again others lead to weird errors, like requesting a subfolder likte /shop/ and either getting a 404 or a https://shop/ couldn't be reached. 再次导致其他错误,例如请求子文件夹likte / shop /以及无法获取404或https:// shop /

But none of them redirected www to non-www. 但是他们都没有将www重定向到非www。 Entering the address with www just always lead to: Server not found in Firefox or Website not reachable in Chrome. 用www输入地址总是会导致:在Firefox中找不到服务器或在Chrome中无法访问网站。

Anyone has any ideas? 有人有什么想法吗?

EDIT: Meanwhile it seemed to have an effect, and www.shop.bitcoinmesse.com is reachable and forwards to https://shop.bitcoinmesse.com . 编辑:同时似乎有效果,并且www.shop.bitcoinmesse.com可以访问并转发到https://shop.bitcoinmesse.com

Unfortunately a subpage like www.shop.bitcoinmesse.com/shop/ is not reachable. 不幸的是,无法访问类似www.shop.bitcoinmesse.com/shop/的子页面。

Try 尝试

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
</IfModule>

Basically right now the back-reference $1 isn't pointing to anything. 基本上现在反向引用$1没有指向任何东西。 I added (.*) to the RewriteRule so that $1 actually was a reference to a capture group in the regex. 我在RewriteRule添加了(.*) ,因此$1实际上是对正则表达式中捕获组的引用。 You could also try just changing $1 to $0 and it would do the same thing since $0 is the full matched URL. 您也可以尝试将$1更改$1 $0 ,由于$0是完全匹配的URL,因此它也可以执行相同的操作。

I also updated the RewriteCond to ensure that the host header has something after www. 我还更新了RewriteCond以确保主机头在www.后面有内容www. . It's a minor change, since the server shouldn't be listening to any host header anyway. 这是次要的更改,因为服务器无论如何都不应该监听任何主机头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM