I'm not the best with mod rewrite so if anybody can help me out here that would be great.
I'm using a markdown processor script and it's using rewrite to grab any files that end with a markdown file type. However, I'd like this script to grab any files within a folder, rather than any files that end with the markdown file type.
Here's the htaccess
:
# display Markdown as HTML by default
RewriteEngine on
RewriteRule .+\.(markdown|mdown|md|mkd)$ /static/includes/markdown/render.php
RewriteRule .+\.(markdown|mdown|md|mkd)\-text$ /static/includes/markdown/render.php [L]
Is there a way to grab all files within a folder called (let's say) "folder" and eliminate the file type on the end?
So maybe have a URL like
website.com/home
that actually is
website.com/home.md
and is processed with the markdown script?
Hope this makes sense.
The re-write module and it's .htaccess
files actually work on a per folder basis. Usually one would have a main .htaccess
file in the web root of a site/server. However you can add numerous .htaccess
files throughout your site's folder structure giving each individual folder specific rules.
All you would have to do is add another .htaccess
file to your markdown folder and enable it to parse URL's without file extensions, forwarding it to a script which will be able to detect what original file was requested -
RewriteEngine on
RewriteRule ^(.*)$ /static/includes/markdown/render.php?file=$1 [L,QSA]
Basically what is happening here is that any file requested within this folder will be passed through your render.php
file.
Now in your render.php
file, you would have a $_GET
parameter of file
containing the original URL. For a url of http://example.com/markdown/foo
, your render.php
would have foo
in the file
parameter -
/static/includes/markdown/render.php?file=foo
If you set the correct headers in render.php
it will be able to print out any format of file, hiding it's extension in a "fake" URL.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.