首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将www改为非www

将www改为非www
EN

Stack Overflow用户
提问于 2015-05-09 22:40:52
回答 2查看 1.1K关注 0票数 1

为了我的论坛,我试图将www网址重定向到非www。我的论坛安装在一个名为“论坛”的子目录中。在我的根目录中安装了WordPress。对于根目录中的WordPress,.htaccess重定向工作正常,但我很难让它在我的论坛上工作。

我尝试过一些我在谷歌搜索中发现的规则,但它们没有奏效。

我还检查了这个主题Generic htaccess redirect www to non-www

但在我的例子中,htaccess文件位于子目录中,而不是根目录中。

可能我做错了什么,所以下面是我的整个.htaccess文件:

代码语言:javascript
复制
#   Mod_security can interfere with uploading of content such as attachments. If you
#   cannot attach files, remove the "#" from the lines below.
#<IfModule mod_security.c>
#   SecFilterEngine Off
#   SecFilterScanPOST Off
#</IfModule>

ErrorDocument 401 default
ErrorDocument 403 default
ErrorDocument 404 default
ErrorDocument 405 default
ErrorDocument 406 default
ErrorDocument 500 default
ErrorDocument 501 default
ErrorDocument 503 default

<IfModule mod_rewrite.c>
RewriteEngine On

#   If you are having problems with the rewrite rules, remove the "#" from the
#   line that begins "RewriteBase" below. You will also have to change the path
#   of the rewrite to reflect the path to your XenForo installation.
RewriteBase /forum
RewriteCond %{HTTP_HOST} www.example.com$
RewriteRule ^(.*)$ http://example.com/forum$1 [R=301,L]


#   This line may be needed to enable WebDAV editing with PHP as a CGI.
#RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
RewriteRule ^.*$ index.php [NC,L]


</IfModule>

任何帮助都是非常感谢的。谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-05-10 04:58:38

您需要将您的www删除规则替换为以下规则:

代码语言:javascript
复制
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [NE,R=301,L]

请确保在新浏览器中对此进行测试,以避免旧缓存。

票数 1
EN

Stack Overflow用户

发布于 2015-05-09 22:49:55

将此代码放在.htaccess文件中:

代码语言:javascript
复制
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30145779

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档