Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML 301 Redirect in Google App Engine

I have 4 URLs that I would like to redirect to my main page. They are all just common misspellings and I want to have my bases covered so that users can access the site even if they have a letter off. How would I go about doing this with Google App Engine?

I would imagine that I need a python handler to do the redirects but what would this look like? Any resources or examples would be great.

like image 510
clifgray Avatar asked Oct 01 '12 20:10

clifgray


People also ask

How do I create a 301 redirect in HTML?

To 301 Redirect a Single Page:html with the file name of the page you want to be redirected. If the file is not in the top-level of the directory, then include the file path in front of the /old-file. html. Replace http://www.domain.com/new-file.html with the URL you want the page redirected to.

Does Google like 301 redirects?

If they are, you'll want to redirect (301) that page to another relevant resource on your website. Redirecting 404 pages to somewhere relevant is key. Google treats irrelevant 301 redirects as soft 404's, so there's no real advantage of redirecting unless you're doing so to a similar and relevant page.

How do I fix 301 redirects?

Fix Any Broken Redirects Access your website sitemap. Download a list of your URLS. Filter the list for any 301 status codes. Bring back the pages that no longer exist or update the URL to reflect the correct page it should be redirected to.


1 Answers

You can simply use the self.redirect() and your request will be handled correctly.

class PageHandler(webapp.RequestHandler):
  def get(self):
    self.redirect('/home/', permanent=True)

You can also set a custom status using the self.response.set_status(301). I would suggest you reading more in the docs: Redirects, Headers and Status Codes.

like image 169
Lipis Avatar answered Nov 07 '22 09:11

Lipis