Created
April 27, 2012 14:50
-
-
Save fideloper/2509880 to your computer and use it in GitHub Desktop.
htaccess to display markdown only if file exists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Turn on Rewrite | |
RewriteEngine On | |
#Check if requested file ends in .md or .markdown | |
RewriteCond $1 \.(md|markdown)$ [NC] | |
#Check if file exists | |
RewriteCond %{REQUEST_FILENAME} -f | |
#Rewrite so $_GET['file'] is available to PHP code | |
RewriteRule ^(.*)$ /index.php?file=$1 [L] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
For files in web root: | |
index.php | |
file.md | |
file2.md | |
**********************************/ | |
/* | |
Allows users such as: http://mysite.com/file.md | |
Which would effectively become: http://mysite.com/index.php?file=file.md | |
**********************************/ | |
/* | |
Files which do not exist will give a 404 error | |
http://mysite.com/some_random_file.md #Yields 404 error | |
http://mysite.com/index.php?file.md #Works - Still need to check in code if file_exists(); | |
**********************************/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment