Is there a Drupal module that can redirect from root URL to a certain page?
I wonder if there's a Drupal module that can do this kind of functionality: if i go to home page, it will take me to some subpath within the site. i.e. www.something.com will redirect to www.something.com/product/node/11.
I tried creating a开发者_如何学JAVAn alias and used Path redirect module but for some reason, i can't reach the expanded URL when going to home page. it will display the content of www.something.com/product/node/11 but still using www.something.com.
I'm thinking that this can only be implemented in Apache server, not inside Drupal?
Note that our purpose of doing this feature is whenever a new product is created, we want our home website to point to that (i.e. www.something.com -> www.something.com/product2/home, before www.something.com/product1/home). If this is configurable inside Drupal, the changes would be easier and can be done by a Drupal administrator.
You should be able to go to /admin/settings/site-information
and set the Default Front Page at the bottom of the form. That doesn't do a redirect: the home page will BE whatever you set the default to.
- Create a new view (Node type) named "frontpage_redirect"
- As suggested in answer by Michael D, create and save a view configured to search for your specified criteria:
- display: page display, path = frontpage-redirect
- pager: 1 item
- row style = Fields
- fields: Node => Node ID
- filters: node type = product
- sort: post date desc
- Save your new view
- At
admin/config/system/site-information
, set your "Default front page" to the view display path above (frontpage-redirect in my example) - In the view edit screen select "Theme: Information" link in the Page display. Look for the most specific (rightmost) entry under "Field Node: Nid (ID: nid)" - should be something like
views-view-field--frontpage-redirect--page-1--nid.tpl.php
, but will depend on the view name and display name. Copy the default views template views-view.tpl.php into your theme folder using the filename from 3. - Edit the template and put this code in it:
if (isset($row->nid)) { drupal_goto('node/' . $row->nid); }
This way of setting up the redirect lets you drive it from Views, which gives flexibility. When your customer decides in six weeks that they want to feature only the latest red product on the frontpage, you'll be able to update the logic behind the redirect using the views UI. (And you can do it from your phone on the train home!)
You avoid the need to create a custom module (which is easy enough, but does add some complexity) or to move your site logic into .htaccess
.
Using the Views module, create a new view that displays one full node, ordered by last created, filtered appropriately, then create a page display in the view. Then follow Graham's instruction to set the site homepage to the view URL.
Another way would be to write a very simple custom module that db-queries for the latest node created of the sort you want, grab the URL to the page, then redirect there using drupal_goto().
There are other ways to do what you want inside Drupal, but I can't think of any that are more direct and simple at the moment...
What you are asking seems wrong. Sorry if I misunderstand some detail, but it seems you should reconsider the problem on a higher level.
If I understand you right, you want to show the page for the latest product as the homepage? If so, maybe you should turn that into show the latest project page on the homepage. That fits a lot better with the RESTfullness of the web. And with expectations of the users.
The pattern would then be:
- GET /products/22 shows product 22
- GET /products/23 shows product 23
- GET /product/latest shows the last product (in this case, the page would be exactly similar to /products/23)
To achieve that, you can use views module.
On similar lines to Michael D's post, assuming you want to pull the most recently published product from a custom content type called "products," you could put something like this in your settings.php:
function yourtheme_preprocess_page(&$variables) {
$query = db_query("SELECT nid FROM {content_type_products} ORDER BY nid DESC LIMIT 1");
while ($row = db_fetch_object($query)) {
$redirect_nid = $row->nid;
}
if ($variables['is_front'] == 1) drupal_goto("/node/" . $redirect_nid);
}
modify the .htaccess file. http://drupal.org/node/50322#comment-2456576
精彩评论