好的,我知道这个问题还没有得到很好的回答,但是我已经使用了很多不同的解决方案,但是没有一个对我有帮助。
我试图在我的htaccess中使用mod_rewrite将所有www.domain.com重定向到domain.com,这已经足够了。
该网站是一个wordpress网站,它一直为我工作,没有任何问题使用以下任何一个
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]或
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com [nocase]
RewriteRule ^(.*) http://domain.com/$1 [last,redirect=301]我也试过一些其他的,但似乎都没有用!
同样值得注意的是,在wordpress的htaccess中也有以下内容
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]我还检查了是否启用了mod_rewrite,并且它似乎是基于尝试过的rewrite is enabled in php? (克里斯蒂安·罗伊的解决方案)中的方法。
服务器是一个带有Ubuntu12.10的小水滴,带有数字海洋,如果这有帮助的话?我遵循本指南以确保.htaccess被激活https://www.digitalocean.com/community/articles/how-to-use-the-htaccess-file (主要更改是将AllowOveride更改为ALL)。
有什么想法吗?我在这个阶段迷路了!
谢谢
根据请求更新htaccess文件内容
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress**用虚拟主机文件更新**
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /home/wordpress/public_html
Servername domain.com
ServerAlias www.domain.com
<Directory /home/wordpress/public_html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
发布于 2013-12-30 18:45:45
它会起作用的,但你需要确保两件事:
www removal rule放在常规WP规则之前的第一个规则。permalink settings,使其具有无www的博客/家庭地址发布于 2013-12-30 20:14:15
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]应该这么做。正如之前所建议的,它可能应该在特定WP重写之前完成。
https://stackoverflow.com/questions/20845472
复制相似问题