URL Redirect Configuration in Virtualhost for a Single Page Web Application

Posted by fenderplayer on Server Fault See other posts from Server Fault or by fenderplayer
Published on 2012-12-01T08:26:35Z Indexed on 2012/12/01 11:08 UTC
Read the original article Hit count: 301

Filed under:
|
|
|

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&param2=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 [email protected]
     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.

© Server Fault or respective owner

Related posts about apache2

Related posts about virtualhost