2011-05-14 36 views
2

我想将非www前缀页面重定向到www前缀页面。以正确的方式从非www到www网站以.htaccess重定向

但是,我必须在香草论坛中做到这一点,它已经在htaccess中有很少的重定向规则。

我在它上面添加了重定向代码。我想知道这是否正确?它工作正常,但我感觉性能问题,因为论坛加载非常缓慢。


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

    # Certain hosts may require the following line. 
    # If vanilla is in a subfolder then you need to specify it after the /. 
    # (ex. You put Vanilla in /forum so change the next line to: RewriteBase /forum) 
    # RewriteBase /forum 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule ^(.*)$ index.php\?p=$1 [QSA,L] 

谁能帮我告诉这不是标准的或做的更好的方法。

PS:论坛不在根目录下,而是在名为'forum'的文件夹中。在根目录已经有WordPress的博客。

+0

一切看起来都很好。在论坛加载时遇到的任何缓慢,我不会归因于你的'.htaccess'的增加。事实上,对我来说这似乎相当快(<3s)。 – Marcel 2011-05-14 11:27:50

+0

这个.htaccess文件位于何处? – Gumbo 2011-05-14 11:52:31

回答

2

这是我的重定向代码:

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

看起来是一样的。我不认为这是你的性能问题的原因。

0

无论你做什么,都是在.htaccess级别将非www页面重定向到www页面的标准方法。没有其他更好的方法。

0

你不需要编辑htaccess。您可以通过在设置中指定首选网址来更安全地执行此操作。

enter image description here

如果你有domain.com并希望将用户重定向到www.domain.com,然后继续www.domain.com IIN的设置,反之亦然。 WordPress将管理www重定向。

相关问题