0

I have an angularjs app that uses Angular UI Router and the URL that are created have a # in them.. Eg. http://localhost:8081/#/login. I am using Python Simple HTTP server to run the app while developing. I need to remove the # from the URL. I know how to remove it by enabling HTML5 mode in angular. But that method has its problems and i want to remove the # from the server side.

How can i do this using Python Simple HTTP Server?

4
  • 2
    possible duplicate of stackoverflow.com/questions/16677528/… see also scotch.io/quick-tips/… Commented Apr 29, 2015 at 9:11
  • No its not. I know how to remove it from angularJS. but as i said, It creates problems. I have faced it. Take a look at this Commented Apr 29, 2015 at 9:20
  • Ah sorry, I didn't read properly. I have been struggling with this issue with Python Simple HTTP Server myself, I did not find a solution. I did however manage to do it with NodeJS http-server. Commented Apr 29, 2015 at 9:29
  • Question is not clear. Url string is client side property and all that server can do - change the logic how to parse provided route, but not change url on the client side. Here is only one visibly for me way: generate 301 HTTP response of the server with fixed url, but there no guarantee that angularjs will not append # again. Commented Apr 29, 2015 at 11:57

3 Answers 3

1

You can derive from BaseHTTPRequestHandler and override the do_GET method.

class MyHTTPHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        # do your own processing further, if you want to pass it back to
        # default handler with the new path, just do the following
        self.path = self.path.strip('/#')
        BaseHTTPRequestHandler.do_GET(self)
Sign up to request clarification or add additional context in comments.

Comments

0

Well i had a similar problem but the difference is that i had Spring on the Server Side.

You can capture page not found exception at your server side implementation, and redirect to the default page [route] in your app. In Spring, we do have handlers for page not found exceptions, i guess they are available in python too.

Comments

-3

You could catch the string that represends the webadres adres, and if there is a # in replace it with a empty character.

stringA = 'http://localhost:8081/#/login'
stringB = stringA.replace("#", "")
print(stringB)

4 Comments

Yes. If you don't like my answer, well sorry. But I am just trying to help. And there are more roads to Rome. :-)
I know you are trying to help. Your answer doesn't make sense that's why i asked. I wanted to remove the # from the URL when it runs on the SimpleHTTPServer just like it can be done in IIS and Apache. I have no knowledge in python so if this is a part of a larger answer add it.
Then why did you add a python tag to it?
You should add an explanation to your answer.

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.