I’m working on a pretty complex project, so I’d like to go with a file/folder structure that makes sense.
The folder/file structure I’d like to have is:
.htaccess
/php/
/assets/
I’d like to have the web pages that people will access in:
/php/views/pages/
I’m wondering if it’s possible to use just .htaccess to set /php/views/pages as the “viewable root”, so that for example, when people visit http://mydomain.com/ they’ll be viewing http://mydomain.com/php/views/pages/index.php, and if so, how would I go about doing it?
Also, is it possible to canonicalize all access to /php/views/pages using .htaccess and a 301 redirect to stop multiple links being indexed in search engines?
If you don’t have access to your host configuration
DocumentRootcan only be used in server and virtual host configs, .htaccess it must be.Let’s add directives in your .htaccess
I assume you want to let the requests to /assets go through
If a request tries to access
/php/views/pages/directly, redirect it to its canonical versionAnd add a rule to map everything else to
/php/views/pages/If you have access to your host configuration
Forget about .htaccess files and use it. A sample configuration could look like