开发者

Redirect from non-www to www site in .htaccess in proper way

I would like to redirect non-www prefix pages to www prefix pages.

However, I have to do this in vanilla forum which already has few redirect rules in htaccess.

I have added the 开发者_StackOverflow社区redirect code above it. I would like to know whether this is correct? It is working fine but I feel performance problem as the forum is loading really slow.


    <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]

Can anyone help me telling this is not standard or the better way of doing it.

PS: The forum is not at the root but in folder named 'forum'. At root there is already wordpress blog.


This is my redirect code:

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

Looks the same. I don't think this is the cause of your performance problems.


Whatever you have done is the standard method of redirecting a non www page to its www page at the .htaccess level. There is no other better way of doing it.


You don't need edit htaccess. You can do it more safely by specifying the preferred URL in Settings.

Redirect from non-www to www site in .htaccess in proper way

If you have domain.com and want users to be redirected to www.domain.com , then keep www.domain.com iin the settings and vice versa. Wordpress will manage the www redirection.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜