Login / Status
developer.Resource
Home . Documentation . Document Library . Extension Manuals
Sponsors
hosted by punkt.deTYPO3 and Open Source MagazineAOE Media

1.4. Appendix

mod_rewrite notice from Ole Tange, www.fi.dk

When using RealUrl you will need a rewrite rule in .htaccess (or apache.conf) that rewrites the path to index.php. This will do that:

  RewriteRule .* /index.php

However, Apache should not rewrite documents located in /typo3/, /uploads/, /fileadmin/ and /typo3conf/:

  RewriteRule ^typo3/.*$ - [L]
  RewriteRule ^uploads/.*$ - [L]
  RewriteRule ^fileadmin/.*$ - [L]
  RewriteRule ^typo3conf/.*$ - [L]

Also /typo3 (without trailing '/') should not be rewritten:

  RewriteRule ^typo3$ - [L]

If you have a PDF-file that you want to give a nice URL (e.g. www.example.com/project-name/report.pdf) you would want to put it in /project-name/. Therefore files that do exist should not be rewritten either:

  RewriteCond %{REQUEST_FILENAME} !-f

If you use a symlink to the file then this should not be rewritten either:

  RewriteCond %{REQUEST_FILENAME} !-l

If www.example.com/project-name is not a file then it should be considered as a directory so that a relative link to 'background' will be a link to www.example.com/project-name/background and not to www.example.com/background

To force this you simply append a '/' to the url if it is not a file:

  RewriteRule (.*[^/])$ http://%{HTTP_HOST}/$1/ [L,R]

This works by redirecting the browser from www.example.com/project-name to www.example.com/project-name/

If in the directory project-name there is an index.html we should use that instead of Typo3:

  RewriteCond %{REQUEST_FILENAME}/index.html -f
  RewriteRule / %{REQUEST_URI}/index.html [L]

The same goes for index.htm and index.php:

  RewriteCond %{REQUEST_FILENAME}/index.htm -f
  RewriteRule / %{REQUEST_URI}/index.htm [L]
  RewriteCond %{REQUEST_FILENAME}/index.php -f
  RewriteRule / %{REQUEST_URI}/index.php [L] 

The resulting .htaccess looks like this:

  RewriteEngine On
  RewriteRule ^typo3$ - [L]
  RewriteRule ^typo3/.*$ - [L]
  RewriteRule ^uploads/.*$ - [L]
  RewriteRule ^fileadmin/.*$ - [L]
  RewriteRule ^typo3conf/.*$ - [L]
  
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-l
  RewriteRule (.*[^/])$ http://%{HTTP_HOST}/$1/ [L,R]
  RewriteCond %{REQUEST_FILENAME}/index.html -f
  RewriteRule / %{REQUEST_URI}/index.html [L]
  RewriteCond %{REQUEST_FILENAME}/index.htm -f
  RewriteRule / %{REQUEST_URI}/index.htm [L]
  RewriteCond %{REQUEST_FILENAME}/index.php -f
  RewriteRule / %{REQUEST_URI}/index.php [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-l
  RewriteRule .* /index.php

Please note that the order is important. Changing the order will most likely give undesired results.

Using httpd.conf for setting it up, a tip from Stefan Bühler (copy-paste from bugtracker)

    I now have a solution for htttpd.conf:
 --------------
 RewriteRule ^/(typo3|typo3temp|typo3conf|t3lib|tslib|fileadmin|uploads|showpic\.php)(/.*)?$ - [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-l
 RewriteRule ^/(.*)$ /index.php [L,E=ORIG_SCRIPT_NAME:/index.php]
 ---------------
 This sets the environment variable "ORIG_SCRIPT_NAME" to "/index.php" which Typo3 uses (if present) instead of "SCRIPT_NAME".
 "SCRIPT_NAME" is only changed to this if you use .htaccess with RewriteBase, and it is not possible (as far as i know and tried) to change this from httpd.conf.
 If your Typo3 is reachable e.g. at http://host/path-to-typo3/, [^] you would change the RewriteRule to:

 RewriteRule ^/(.*)$ /index.php [L,E=ORIG_SCRIPT_NAME:/path-to-typo3/index.php]