URL Rewriting using .htaccess on Apache2 server


#1

Hello I’m using ember CLI version 2.10.1 I have a route ex: mywebsite/car and i use query string to get the item by ID so the URL is like mywebsite/car?carID=1

I want to create a Rewrite Rule so the URL will be as the following mywebsite/car/1

the website is hosted on apache2 server and i have rewrite mode ON and i created .htaccess file with the below rule RewriteEngine on RewriteRule ^car/([A-Za-z0-9]+) car?carID=$1

it always return 500 error, any idea? Thanks


#2

My guess is that it has something to do with the fact that Ember routes are really just ‘in-page’ navigation using hashes. By default Ember sets the locationType to ‘auto’ so it can be easy to forget that all of your ember routes are actually on a single HTML page loaded from a single server endpoint/address.

The url mywebsite/car?carID=1 actually maps to mywebsite/#/car?carID=1. I’m not very knowledgable about apache (we just serve from S3) and so I can’t tell you exactly what you’ll need to configure. Maybe Apache has some config options for serving a single page app, maybe you simply need to take the hash into account when you make your rewrite rules somehow, maybe you’ll need to change the locationType from ‘auto’ to ‘hash’ in your Ember config/environment.js file… I’m not really sure, sorry!

I’m guessing your issue has something to do with the single page application hash thing though.


#3

I think fixing this in Apache is not transparent if you look back a year later. I think you can create this url in the Ember router and just use the basic .htaccess in your public folder. See also: