开发者

help with php urls

I have a PH开发者_JAVA技巧P web site that has two directories: An application directory and a public directory.

The problem is that the user has to go to www.domain.com/public to access the site but I need the user who asks for www.domain.com/ to be redirected to www.domain.com/public

So my question is what is the best way to do this?


I would do this with a .htaccess rewrite rule. This ensures that the user is always redirected, even if index.php is not requested. Something like this should work for you:

RewriteCond %{REQUEST_URI} !public/
RewriteRule ^(.*)$ public/$1 [L] 


multiple ways - .htaccess, or a simple

<?php header('Location:http://www.domain.com/public'); ?>

would do the trick if you don't need to access anything directly from domain.com explicitly


You should deal with this through your web server (IIS/Apache/otherwise), as it is much better suited and appropriate for this sort of task. SO has plenty of answers on URI redirection for various webservers.

...Also, if you're keeping people out of your "application directory" (which you seem to indicate is your web root), you should really re-design that if your intent is to keep people out of that folder: it's a security risk.


You can solve it in a .htaccess file as well. Just create a "Redirect" rule:

Redirect 301 / /public/


You could do a redirect with PHP. Inside your index.php in your main document root:

<?php

header('Location: public');
die();

?>


put an index.php in / containing:

<?php
header('Location:http://domain.com/public');
?>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜