0

I need to parse parameters in the URL that come in this form:

localhost:8080/p/a=12345&b=acbd

After the variables are read, I load a HTML file that is in the public folder of my express server. That works ok. The problem is that my HTML file load several JS and CSS files and since the path is localhost:8080/p/ the files with relative paths can't be found.

What I need is something similar to the apache URL rewrite, where I can send the traffic to a specific file and change the URL to look in the way I want. I haven't found a node module that does that, any suggestions?

2
  • I don't get it. You mean that you've put links to JS files relative to current URL rather then current domain? Why would you do that in the first place? Commented Nov 21, 2012 at 15:50
  • in my .html I have the relative paths because it makes more sense when you have multiple development stages like development, testing ad production. In this scenario you need to be able to run your code on multiple subdomains without changing the code. Also very useful for running the application on a local machine using localhost and the same code on a server using a domain. Commented Nov 21, 2012 at 19:17

1 Answer 1

0

If you are using the static middleware to serve your static files, you can use

app.use('/p', express.static(__dirname + '/public'));

instead of

app.use(express.static(__dirname + '/public'));

You can see more details in the document of the Express

Sign up to request clarification or add additional context in comments.

2 Comments

I'm already doing that. My problem is not how to redirect, my question is about how to do URL rewriting.
I want my URL to look like this: localhost/acb/123 but I want ti to point o localhost/index.html?a=abc&b=123

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.