mod_rewrite的和双斜线问题 [英] mod_rewrite and double slash issue

查看:116
本文介绍了mod_rewrite的和双斜线问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应用了的Apache2 以下的mod_rewrite 规则从非WWW重定向到www:

I applied the following mod_rewrite rule in Apache2 to redirect from non www to www:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]

我有两个问题:

1)有一个双斜线问题:

1) There's a double slash issue:

  • When I go to http://www.mydomain.com it correctly rewrites the URL to http://www.mydomain.com/
  • When I go to http://www.mydomain.com/somepage, it correctly rewrites the URL to http://www.mydomain.com/somepage
  • If I go to http://mydomain.com, it rewrites the URL to http://www.mydomain.com// (double final slash)
  • If I go to http://mydomain.com/somepage, it correctly rewrites it to http://www.mydomain.com/somepage

任何提示修复它?

2)是对搜索引擎优化我的配置好?

2) Is my configuration good for SEO?

感谢

推荐答案

与修正:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.com$1 [R=301,L]

由于 $ 1 默认包含索引路径 /

because $1 by default contains the index path /

这篇关于mod_rewrite的和双斜线问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆