如何将请求重定向到example.com到www.example.com与mod_rewrite的? [英] How to redirect requests to example.com to www.example.com with mod_rewrite?
问题描述
这是我的.htaccess通过文字preSS的坐在我的根目录下生成。
This is my .htaccess generated by wordpress that sits in my root directory.
我需要修改/添加到它,所有的传入流量定向到的 www.example.com 的,而不是 example.com 的。
I need to modify/add to it, to direct all incoming traffic to www.example.com, instead of example.com.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
如果有人想解释什么上述所有不还,这将是AP preciated为好。
If someone wants to explain what all the above does also, that would be appreciated as well.
推荐答案
做你的要求,你要添加:
To do what you requested, you want to add:
RewriteCond %{HTTP_HOST} ^www.mysite.com$ [NC]
RewriteRule ^(.*)$ http://mysite.com/$1 [R=301,L]
您可以放置其间的&LT; IfModule mod_rewrite.c&GT;
括号后的的RewriteBase
You can place that inbetween the <IfModule mod_rewrite.c>
brackets after RewriteBase
至于什么字preSS'htaccess的code做(没有测试):看来,以测试对任何直接链接到的文件和目录,而不是通过它通常会采取重写规则通过他们你链接并将其发送到index.php
As for what Wordpress' htaccess code does (didn't test it): It seems to test for any direct links to files and directories and not pass them through the RewriteRule which will normally take your link and send it to index.php
所以,如果你的链接是www.mysite.com/some/page,它确保/一些/页不是直接的文件链接或实际的Web目录,如果没有,那么它传递请求到的index.php它解析它,以显示正确的单词preSS页。
So if your link is for www.mysite.com/some/page, it makes sure /some/page isn't a direct file link or an actual web directory and if it isn't, then it passes the request to index.php which parses it to display the correct Wordpress page.
这篇关于如何将请求重定向到example.com到www.example.com与mod_rewrite的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!