开发者

Using .htaccess to redirect only traffic to the root to a specific page

I have a site set up complete with an index, etc. I would like to redirect only traffic coming directly to www.example.com to www.example.com/foo.php. However, if a user tries to access www.exampl开发者_Go百科e.com/index.php or any of the other existing pages directly, the request should return the appropriate page as normal. I can't seem to wrap my head around these rewrite rules. How would I accomplish this with .htaccess?


You could likely get away with just changing the DirectoryIndex to /foo.php:

DirectoryIndex foo.php

However, if you wanted to use mod_rewrite to actually rewrite the URL, there are a few different ways to accomplish this, but the clearist is to just check if the requested resource is an empty string (the root was requested, and the input to RewriteRule in .htaccess files doesn't contain a leading slash):

RewriteEngine On

RewriteRule ^$ /foo.php

Any request to the server that is not for / will simply be ignored and routed by Apache as normal.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜