I am developing an app in RoR which has static and dynamic parts. The static portion is placed in the public/ folder of the app. Now if i have an index.html in my public folder then i will not be able to use the routes configured in my routes.rb The default configurations like map.connect /:controller/:action will not be usable if i have an index.html. So i removed the index html.
Now i have a static page startpage.html in my public/ folder which has to be the starting page of th开发者_高级运维e app. And the i have links in it for other static/dynamic pages.
The RoR app is hosted in apache and i tried to configure the Virtual Host configuration by adding the DirectoryIndex param so that when ever a request comes for the site it will direct it to the startpage.html but still it takes me to the default controller that i have specified in routes.rb with map.root
I dont want to add a dummy controller and action and create a view which has the startpage and configure routes.rb to use it as the root. What i am looking to do here is
Basically startpage.html should be my first page in the app served as a static page from the public/ folder. This will then have links to other pages and controllers/actions
Here i am not able to apache to redirect to the html page instead of passing on the control to rails application. Directory listing is also enabled by using Options Indexes but still no change.
Any pointers anyone?
Now if i have an index.html in my public folder then i will not be able to use the routes configured in my routes.rb.
This is incorrect. The solution of your problem is to rename startpage.html
to index.html
, which will cause requests for /
to be served by index.html
, and any requests for /:controller/:action
will be passed along to Rails Routing engine.
Apache will first serve anything it can find in the public
directory. If it's not available, then it passes the request off to Rails (this is how page caching works).
With index.html
in place, you do not need map.root
, as it will never get requested (remember, Apache serves /
with index.html
). And you don't need any special directives either.
You can made a URL rewrite from index.html to your startpage.html
RewriteRule /index.html /startpage.html
精彩评论