为了我的论坛,我试图将www网址重定向到非www。我的论坛安装在一个名为“论坛”的子目录中。在我的根目录中安装了WordPress。对于根目录中的WordPress,.htaccess重定向工作正常,但我很难让它在我的论坛上工作。
我尝试过一些我在谷歌搜索中发现的规则,但它们没有奏效。
我还检查了这个主题Generic htaccess redirect www to non-www
但在我的例子中,htaccess文件位于子目录中,而不是根目录中。
可能我做错了什么,所以下面是我的整个.htaccess文件:
# 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>任何帮助都是非常感谢的。谢谢
发布于 2015-05-10 04:58:38
您需要将您的www删除规则替换为以下规则:
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [NE,R=301,L]请确保在新浏览器中对此进行测试,以避免旧缓存。
发布于 2015-05-09 22:49:55
将此代码放在.htaccess文件中:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]https://stackoverflow.com/questions/30145779
复制相似问题