Note that there are some explanatory texts on larger screens.

plurals
  1. POApache: How to rewrite URL with no file extension and ignore case?
    primarykey
    data
    text
    <p>I'm running Ubuntu 12.04 with Apache 2.2.22 and PHP 5.3.10. I'd like users to be able to request pages on my site without having to type the '.php' extension, and without having to worry about case sensitivity. For example, URLs like these...</p> <pre><code>http://www.site.com/test/phpinfo http://www.site.com/test/PhPiNfO </code></pre> <p>...should both lead to:</p> <pre><code>http://www.site.com/test/phpinfo.php </code></pre> <p>I started with case insensitivity by following the accepted answer in <a href="https://stackoverflow.com/questions/2923658/convert-to-lowercase-in-a-mod-rewrite-rule">this question</a>. Here's what my '/etc/apache2/sites-available/default' file looks like...</p> <pre><code>&lt;VirtualHost *:80&gt; ServerAdmin webmaster@localhost DocumentRoot /var/www RewriteMap lc int:tolower &lt;Directory /&gt; Options FollowSymLinks AllowOverride All &lt;/Directory&gt; &lt;Directory /var/www/&gt; Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all &lt;/Directory&gt; &lt;Directory /var/www/test&gt; Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all &lt;/Directory&gt; ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ &lt;Directory "/usr/lib/cgi-bin"&gt; AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all &lt;/Directory&gt; ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined Alias /doc/ "/usr/share/doc/" &lt;Directory "/usr/share/doc/"&gt; Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 &lt;/Directory&gt; &lt;/VirtualHost&gt; </code></pre> <p>...and here's my .htaccess file:</p> <pre><code>RewriteEngine On RewriteRule ^([a-z]+)/([a-z\-]+)$ /${lc:$1}/${lc:$2}.php [L,NC] </code></pre> <p>The file extension part is working, but for some reason case sensitivity is still being enforced. My Apache error log is filled with lines like this:</p> <pre><code>[Sat Jan 05 23:10:41 2013] [error] [client 192.168.1.9] File does not exist: /var/www/test/phpinfO </code></pre> <p>Any ideas what I'm doing wrong here?</p> <p><strong>EDIT:</strong> After experimenting for a couple hours, I'm seeing the most bizarre behavior! I thought maybe my .htaccess file was simply being ignored, so I filled it with gibberish. This produced an internal server error as expected. I then tried just these two lines in my .htaccess file...</p> <pre><code>RewriteEngine On RewriteRule ^/(.*)$ /${lc:$1} </code></pre> <p>...and tried to access test/phpinfO.php unsuccessfully. I then deleted the .htaccess file and put those two lines directly into my '/etc/apache2/sites-available/default' file and restarted Apache. For some inexplicable reason, the behavior I wanted is now working! I can't <em>possibly</em> fathom how, since my only rule doesn't append '.php' to the URL!</p> <p>This may sound odd, but it almost feels like my changes are taking effect in some delayed way. I tried some other tests that didn't work right away, but that seemed to work later when they shouldn't have. I keep testing and expecting my current setup to break without changing anything. Whatever the case, I am absolutely baffled.</p> <p>Hope somebody can shed some f'ing light on this before I rip my brain out and smash it with a sledge hammer.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload