URL Redirect Configuration in Virtualhost for a Single Page Web Application
- by fenderplayer
I have a web application under development that I am running locally. The home page of the application is fetched with the following url:
http://local.dev/myapp/index.shtml
When the app runs, javascript on the webpage maintains the url and the app state internally. Some of the other urls read as:
http://local.dev/myapp/results?param1=val1¶m2=val2
http://local.dev/myapp/someResource
Note that there are no pages named results.html or someResource.html on my web server. They are just made up URLs to simulate RESTfulness in the single page app. All the app code - javascript, css etc - is present in the index.shtml file
So, essentially, the question is how can I redirect all requests to the first URL above?
Here's how the vhost configuration looks like:
<VirtualHost 0.0.0.0:80>
ServerAdmin webmaster@m5.dev
DocumentRoot "/Users/Me/mySites"
ServerName local.dev
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(myapp|myapp2)\/results\?.+$ $1/index.shtml [R=301,L]
<Directory "/Users/Me/mySites/">
Options +Includes Indexes MultiViews FollowSymlinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog "/private/var/log/apache2/error.log"
CustomLog "/private/var/log/apache2/access.log" common
</VirtualHost>
But this doesn't seem to work. Requesting the other URLs directly results in 404 error.