snipt

Ctrl+h for KB shortcuts

Text only

Remove File Extension from URLs in .htaccess

1
2
3
4
5
6
7
8
# Sample 1: 
RewriteRule ^about$ about.php [L]
 
# Sample 2: 
RewriteCond /%{REQUEST_FILENAME}.php -f
RewriteRule ^([a-zA-Z0-9_-\s]+)/$ /$1.php

source: http://apphp.com/index.php?snippet=htaccess-remove-file-extension-from-url

Description

This example shows you how to remove file extension from URLs using .htaccess file directives. Remember, that "mod_rewrite" works only on Apache server. Before trying please be sure that you are working on Apache server and the "mod_rewrite" module/extension is enabled.
https://snipt.net/embed/861d04fa4d31b0d94447aebef2dcc178/
/raw/861d04fa4d31b0d94447aebef2dcc178/
861d04fa4d31b0d94447aebef2dcc178
text
Text only
8
2019-06-18T02:45:45
True
False
False
Feb 16, 2014 at 03:24 AM
/api/public/snipt/114086/
remove-file-extension-from-urls-in-htaccess
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a># Sample 1: </span><span id="L-2"><a name="L-2"></a>RewriteRule ^about$ about.php [L] </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a># Sample 2: </span><span id="L-5"><a name="L-5"></a>RewriteCond /%{REQUEST_FILENAME}.php -f </span><span id="L-6"><a name="L-6"></a>RewriteRule ^([a-zA-Z0-9_-\s]+)/$ /$1.php </span><span id="L-7"><a name="L-7"></a> </span><span id="L-8"><a name="L-8"></a>source: http://apphp.com/index.php?snippet=htaccess-remove-file-extension-from-url </span></pre></div> </td></tr></table>
"remove file extension", apphp, htaccess