开发者

Redirect all page on a domain to one file

I am loo开发者_StackOverflowking to permanently redirect all the pages on a domain to one page on the SAME domain, using htaccess/mod_rewrite.

Basically I want any page requested for the domain to return a holding page [ which is index.php] at domain.com/

most of my attempts so far are causing errors as they are throwing the server intoa loop.

Thanks in advance

.k


You need to exclude the destination you are redirecting to like this:

RewriteEngine on
RewriteRule !^index\.php$ /index.php [L,R=301]

If you just want to redirect requests that can not be mapped to existing files in the filesystem, add this condition:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^index\.php$ /index.php [L,R=301]

But you should rather respond with a 404 in that case.


Here's a simple implementation:

RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css|html)$ index.php

And a bit more sophisticated one:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

Both were taken from Zend Framework Zend_Controller Programmer's Reference Guide. Here's another useful doc Apache Module mod_rewrite.


ISR that this was asked here recently - but I can't find the q right now.

Why not just set up the 404 errorhandler to point to the holding page (and keep all other content out of the doc root)

C.


Thanks to all,

got it working, here it is it might be of help to others:

RewriteRule !^(index.php)|.(js|ico|gif|jpg|png|css|mp3|xml|swf)$ /index.php [L,R=301]

.k

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜