Rail public transit provides passengers with low cost, widely covered, environment-friendly travel service. However, many travelers do not choose the rail public transit because they are hindered by the first mile bottleneck - how to get to the train station. Ridesharing emerges as a viable transportation mode in connection with rail public transit. This paper designs a detour-based discounting mechanism for the first-mile ridesharing service to encourage more passengers to use the rail public transit. Specifically, passengers are incentivized by the mechanism to participate in the first-mile ridesharing service in connection with train stations. The mechanism accounts for passengers' personalized requirement on the detour in determining the optimal vehicle-passenger matching, vehicle routing plan, and the pricing scheme. The New Brunswick train station (a New Jersey Transit station) is selected as the testbed to implement the proposed first-mile ridesharing mechanism. The results verify the application viability of the mechanism and demonstrate that the mechanism is effective to incentivize passengers to use the rail public transit.