Wordpress非www到www将所有网址重定向到家而不是网址

时间:2017-07-24 08:27:10

标签: wordpress .htaccess no-www

我的所有非www网址都会重定向到我的主页

这是我的htaccess

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

2 个答案:

答案 0 :(得分:0)

如果您只是想强迫所有人使用www,那么这应该可以解决问题。

# Needed before any rewriting
RewriteEngine On

# Redirect HTTP without www to HTTP with www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Redirect HTTPS without www to HTTPS with www
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

## 301 Redirects can go after this

答案 1 :(得分:0)

不要忘记在wp_options表格或设置中设置您的域名。

enter image description here

另外,请将这一行放在.htaccess

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^opcito.com [NC]
RewriteRule ^(.*)$ http://www.opcito.com/$1 [L,R=301]

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

希望它能帮助你:)。