htaccess将www重定向到非www而不更改地址 [英] htaccess redirect www to non-www without changing in address
本文介绍了htaccess将www重定向到非www而不更改地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个地址
http://name.com/category/1/news
我在htaccess中使用此代码来强制打开没有www的页面.
I use this code in htaccess to force open page without www.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
当我打开http://www.name.com/category/1/news
时,我将重定向到
When I open http://www.name.com/category/1/news
then I redirect to
http://name.com/category.php?id=1&slug=news
这是我完整的htaccess文件.
Here is my full htaccess file.
RewriteEngine on
RewriteRule ^news/(.*)$ news.php?id=$1&slug=$2
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
谢谢.
推荐答案
尝试:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [NE,R=301,L]
RewriteRule ^news/(.*)$ news.php?id=$1&slug=$2 [NC,L]
这篇关于htaccess将www重定向到非www而不更改地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文