I have a Laravel style MVC webapp. Not written in Laravel, but similar concept.
On my dev box, my webapp lived in its own “domain” with the /public
folder being the document root.
Folder Structure
MyProject
|
+-- App
| |
| +-- Models
| |
| +-- Views
| |
| +-- Controllers
|
+-- public (doc root)
|
+-- htaccess
+-- index.php
I used this .htaccess
file to route all the traffic through the index.php file that lived in public folder.
htaccess
# Remove the question mark from the request but maintain the query string
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
So when you visited http://myinternalproject.com, you could use the webapp fine.
Now, for production, I have to move the project and all of its files to its own folder within our company domain. It cannot be a subdomain as per the Administrator.(Which would fix all my problems.)
So it has to be accessed via www.mydomain.com/apps/myproject/
.
Navigating to: www.mydomain.com/apps/myproject/public
works fine and the site shows up.
Navigating beyond the “home page” causes all the links to go to: www.mydomain.com/{controller}/{action}
instead of living in the new sub-folder.
Is there a way to rewrite all the links in my app to automatically go to /apps/myproject/public
(since that is where the index.php lives) without going through every possible link and prefixing /apps/myproject/public
?
I tried variations on appending the new folder structure to the htaccess
, but can’t get it to work.
RewriteBase /apps/myproject/public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule /apps/myproject/public/^(.*)$ /apps/myproject/public/index.php?$1 [L,QSA]
2
Answers
More about this here
You may use this additional rule in your document root .htaccess:
Then you should keep this rule inside
/apps/myproject/public/.htaccess
: