index.php处理的所有子域和URL

时间:2013-03-02 19:58:10

标签: .htaccess rewrite

我没有成功地尝试进行以下重写。

无论输入什么网址或子网域,都应始终由index.php“处理”。

让我说我去example.domain.com

网址将重新统一,但内容是index.php

中的内容

如果网址或子域名确实存在,则无关紧要。

任何例子都是一样的:

other.domain.com/something

用户应保持不变,但index.php应显示的是什么。

2 个答案:

答案 0 :(得分:1)

您可以在主域(site.com)的根目录下的一个.htaccess文件中尝试此操作:

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI}  !index\.php    [NC]
RewriteRule .*              /index.php?    [L]

# If the above rule doesn't work as expected, use this rule instead:
# RewriteRule .*  http://site.com/index.php? [L]    

这适用于public_html文件夹中托管的通配符和插件子域。

规则集符合问题中的所有要求:

  • "No matter what URL is entered or the sub-domain" 将所有内容重定向到http://site.com/index.php

  • "it should always be processed by index.php"。因此,在index.php的根目录中,http://site.com必须存在于某个地方并且为此答案。

  • "but index.php what is what should be showed"。相当令人困惑,但一个OP评论清楚地表明:将传入的URL保留在地址栏中。如果情况并非如此,请将[L]替换为[R=301,L]

  • 不要将任何内容传递给替换网址中的脚本(index.php),因为OP没有提及。

答案 1 :(得分:0)

您可以在.htaccess中使用以下行:

RewriteEngine on
RewriteRule ^([^/\.]+)/?$ index.php [L]
相关问题