使用mod_rewrite和Apache避免URL规范化
URL规范化是您的网站使用不同的URL输出相同内容的地方。当搜索引擎搜寻器看到所有相同的内容时,他们可能会对在搜索引擎结果页面中显示哪个页面感到困惑。以下URL尽管不同,但实际上产生相同的内容。
http://www.example.com http://example.com http://www.example.com/ http://www.example.com/index.html
解决此问题的方法是使用mod_rewrite将所有请求重定向到单个页面。将.htaccess文件添加到您的根目录,并包括以下行以打开引擎。
RewriteEngineOn
以下规则会将www页面重定向到非www页面。
#Redirecting non-www to www.domain.com:
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]使用以下规则从index.html页面重定向到目录名称。
#Redirecting /index.html to /:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html
RewriteRule ^index\.html$ http://www.domain.com/ [R=301,L]如果要检测是否存在mod_rewrite,可以在if语句中包括所有前面的行,如下所示。
RewriteEngine On #Redirecting non-www to www.domain.com: RewriteCond %{HTTP_HOST} ^domain\.com$ [NC] RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L] #Redirecting /index.html to /: RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html RewriteRule ^index\.html$ http://www.domain.com/ [R=301,L]
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下