htaccess的重定向index.php来根(包括子域) [英] htaccess redirect index.php to root (including subdomains)

查看:117
本文介绍了htaccess的重定向index.php来根(包括子域)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想的index.php文件重定向到根目录/,我搜索了一圈,发现类似code的几个片段:

I'm trying to redirect index.php files to the root /, I've searched around and found several snippets of code similar to:

RewriteCond %{THE_REQUEST} ^.*/index.php 
RewriteRule ^(.*)index.php$ http://www.domain.com/$1 [R=301,L] 

不过,这不会为子域工作,下面的例子:

This however won't work for subdomains, example below:


  1. 我有一个子域:subdomain.domain.com

  2. 的用户访问 http://subdomain.domain.com/index.php

  3. 使用上面,他们将被重定向到 http://www.domain.com/ 而不是的 http://subdomain.domain.com/

  1. I have a subdomain: subdomain.domain.com
  2. A user visits http://subdomain.domain.com/index.php
  3. Using the htaccess above they are redirected to http://www.domain.com/ rather than http://subdomain.domain.com/

有谁知道如何调整上述htaccess的所以它会考虑到子域名,并将其重定向到相应的位置?

Does anyone know how to adjust the htaccess above so it will take into account the subdomain and redirect them to the appropriate location?

例如。如果用户访问 http://subdomain.domain.com/index.php 他们会去的http://subdomain.domain.com/

e.g. if a user visits http://subdomain.domain.com/index.php they will go to http://subdomain.domain.com/

积分:

有没有办法,可以只将此规则应用于所有文件夹一个htaccess的?

Is there a htaccess that can just apply this rule to all folders?

因此​​,对于与index.php的任何文件夹,他们将只被重定向到它的根如<一href=\"http://subdomain.domain.com/folder1/folder2/index.php\">http://subdomain.domain.com/folder1/folder2/index.php会自动转到<一个href=\"http://subdomain.domain.com/folder1/folder2/\">http://subdomain.domain.com/folder1/folder2/

So for any folder with an index.php they will just be redirected to it's root e.g. http://subdomain.domain.com/folder1/folder2/index.php would automatically go to http://subdomain.domain.com/folder1/folder2/

推荐答案

做到这一点:

RewriteCond %{THE_REQUEST} ^.*/index\.php 
RewriteRule ^(.*)index.php$ /$1 [R=301,L] 

这篇关于htaccess的重定向index.php来根(包括子域)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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