htaccess的WWW到无WWW不工作 [英] htaccess WWW to no-WWW not working

查看:182
本文介绍了htaccess的WWW到无WWW不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧我知道这并没有回答很多,但我一直在使用很多不同的不同的解决方案,但他们都不是为我工作。

我试图使用mod_rewrite在我的htaccess的重定向所有www.domain.com为domain.com - 标准不够

该网站是一个字preSS的网站,并使用它总是为我工作没有任何问题的任何以下

  RewriteEngine叙述上
的RewriteBase /
的RewriteCond%{HTTP_HOST} ^ WWW \。(。*)$ [NC]
重写规则^ $ HTTP(*)://%1 / $ 1 [R = 301,L]
 

  RewriteEngine叙述上
的RewriteCond%{HTTP_HOST} ^ www.domain.com [NOCASE]
重写规则^(。*)http://domain.com/$1 [最后,重定向= 301]
 

我已经尝试了一些其他的也没有,但似乎工作!

这也可能是值得铭记以下也从字preSS

htaccess的

 重写规则^指数\ .PHP $  -  [L]
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则。的index.php [L]
 

我还检查,看看是否mod_rewrite的是,即使启用,这似乎是基于在这里尝试的如何检查是否mod_rewrite的是在PHP中启用?(基督教罗伊的解决方案)

服务器的小液滴与Ubuntu 12.10托管与数字海洋是否有帮助?我遵循这个指南,以确保的.htaccess被激活的https:/ /www.digitalocean.com/community/articles/how-to-use-the-htaccess-file (主要变化是改变AllowOveride为ALL)

任何人任何想法?我失去了在这个阶段!

感谢

更新htaccess文件内容的要求

 #BEGIN字preSS
< IfModule mod_rewrite.c>
RewriteEngine叙述上
的RewriteCond%{HTTP_HOST} ^ WWW \。 [NC]
重写规则^(。*)$ http://domain.com/$1 [R = 301,L]
的RewriteBase /
重写规则^指数\ .PHP $  -  [L]
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则。的index.php [L]
< / IfModule>

#结束字preSS
 

*的更新与虚拟主机文件*

 <虚拟主机*:80>
的ServerAdmin网站管理员@本地

的DocumentRoot /家庭/字preSS /的public_html

服务器名domain.com

ServerAlias​​ www.domain.com

<目录为/ home /字preSS /的public_html>
    选择了FollowSymLinks指标多视图
    设置AllowOverride所有
    订购允许,拒绝
    允许所有
< /目录>

的ScriptAlias​​ / cgi-bin目录/ / usr / lib目录/ cgi-bin目录/
<目录/ usr / lib目录/ cgi-bin目录>
    设置AllowOverride无
    选项​​+ ExecCGI -MultiViews + SymLinksIfOwnerMatch
    订购允许,拒绝
    所有允许
< /目录>

错误日志$ {APACHE_LOG_DIR} /error.log

#可能的值包括:调试,信息,通知,警告,错误,暴击,
#警觉,EMERG。
日志级别警告

的CustomLog $ {APACHE_LOG_DIR} /access.log组合
 

解决方案

  RewriteEngine叙述上
的RewriteCond%{HTTP_HOST} ^ WWW \。 [NC]
重写规则^(。*)$ http://domain.com/$1 [R = 301,L]
 

应该这样做。如前告知,它应该做的的WP-具体重写。

Ok I know this hasn't been answered a lot, but I've been using a lot of various different solutions but none of them are working for me.

I'm trying to use mod_rewrite in my htaccess to redirect all www.domain.com to domain.com - standard enough.

The site is a wordpress site, and it's always worked for me without any problems using any of the following

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

Or

RewriteEngine On
RewriteCond %{HTTP_HOST}  ^www.domain.com [nocase]
RewriteRule ^(.*)         http://domain.com/$1 [last,redirect=301]

I've tried a few other ones as well but none seem to work!

It may also be worth bearing in mind the following are also in the htaccess from wordpress

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

I have also checked to see if mod_rewrite is even enabled and it appears to be based on the methods in tried here How to check if mod_rewrite is enabled in php? (Christian Roy's solution)

The server is a small droplet with Ubuntu 12.10 hosted with digital ocean if that helps? I followed this guide to ensure .htaccess was activated https://www.digitalocean.com/community/articles/how-to-use-the-htaccess-file (main change was changing AllowOveride to ALL)

Anyone any ideas? I'm lost at this stage!

Thanks

Updated htaccess file contents as requested

 # 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

*Updated with Virtual Host File *

<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

解决方案

RewriteEngine On
RewriteCond %{HTTP_HOST}  ^www\. [NC]
RewriteRule ^(.*)$   http://domain.com/$1 [R=301,L]

should do it. As advised before, it should probably be done before WP-specific rewrites.

这篇关于htaccess的WWW到无WWW不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆