Reputation: 1053
using Python on a Linux server, I would like to use "smart URLs" also known as "semantic/friendly/SEO URLs" to get content from a python script. But I don't want to create all the files (one for each items depending on the URL subpath).
The data to use are stored in a python dictionary and here is the file location:
http://mysite.com/blog/data.py
Now, I use this system to get the content (with .htaccess):
http://mysite.com/blog?article=myfirst_article_id
>>> return "The content of myfirst_article"
The goal is to do the same thing but without the query string:
http://mysite.com/blog/first_article_id
>>> return "The content of myfirst_article"
Is it possible to do that with python (and without .htaccess) and how?
If not, how to do it with .htaccess?
Upvotes: 1
Views: 1358
Reputation: 599450
Use a web framework. Even a minimal one like Flask will give you proper URL routing with the ability to define your own URL patterns. Plus, it'll almost certainly work much faster than executing your Python scripts via CGI.
Upvotes: 4
Reputation: 4492
With htaccess you can use this rule
RewriteEngine On
RewriteRule ^blog/([0-9]+)$ /blog/data.py?article=$1 [L]
Upvotes: 4