Reputation: 21192
I have a PHP 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?
Upvotes: 0
Views: 106
Reputation: 33511
You can solve it in a .htaccess file as well. Just create a "Redirect" rule:
Redirect 301 / /public/
Upvotes: 1
Reputation: 58962
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]
Upvotes: 3
Reputation: 20765
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.
Upvotes: 1
Reputation: 17967
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
Upvotes: 2
Reputation: 33901
put an index.php in / containing:
<?php
header('Location:http://domain.com/public');
?>
Upvotes: 0
Reputation: 2592
You could do a redirect with PHP. Inside your index.php in your main document root:
<?php
header('Location: public');
die();
?>
Upvotes: 0