使用htaccess删除URL中的所有子目录

时间:2014-10-08 19:21:53

标签: apache .htaccess mod-rewrite redirect expressionengine

我运行一个Expression Engine网站,无论在地址栏中输入任何组成的子目录名称,都会加载文章页面。

例如所有这些地址:

http://hellothere.example.com/health/mental/depression
http://cats.example.com/health/mental/depression
http://dogs.example.com/health/mental/depression
http://www.batman.example.com/health/mental/depression
http://www.1.2.3.4.5.6.example.com/health/mental/depression

将加载example.com/health/mental/depression

显然,这对SEO来说不太理想,因为我有可能无限数量的重复网址。

我试图找出如何使用htaccess在example.com之前删除任何东西,并用www替换它。

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

你不能用htaccess做到这一点。执行此操作的方法是设置通配符dns记录,以便将所有请求(* .example.com)全部定向到同一服务器。

请参阅http://codex.wordpress.org/Configuring_Wildcard_Subdomains