【发布时间】:2014-01-03 06:14:13
【问题描述】:
好的,我知道这个问题没有得到很多回答,但我一直在使用很多不同的解决方案,但没有一个对我有用。
我正在尝试在我的 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 是否已启用,它似乎基于此处尝试的方法How to check if mod_rewrite is enabled in php?(Christian Roy 的解决方案)
如果这有帮助,服务器是一个带有 Ubuntu 12.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
【问题讨论】:
标签: wordpress apache .htaccess mod-rewrite