[Typo3-dev] Bug in .htaccess?

Martin Poelstra martin at beryllium.net
Fri Apr 30 19:15:52 CEST 2004


> Conclusion: I'd suggest to:
> - Leave out the RewriteBase alltogether and move the text about adding the
> path_to_typo to the RewriteRule (including prepending slash). That works
> with BOTH virtualhost (httpd.conf) AND .htaccess.
> - Change the '.*\.(html|pdf)$' to just '.*': easier to read and works for
> both config-ways.

Btw: I tested it with TYPO3 installed in the webroot, and also installed in
a subdirectory.
In both cases I tried the .htaccess and httpd.conf-ways.

I did some more testing, because I wasn't sure anymore if the rules for the
typo3-dir actually worked (because the urls are left alone anyway because
the files do exist).

##########################
The .htaccess-case:

Removing the RewriteBase works OK, if I add the path_to_typo as:
RewriteRule .* /path_to_typo/index.php
The typo3-dir rules also work correctly, i.e., Apache immediately stops
rewriting when the URL starts with typo3/.

##########################
The httpd.conf-case:

Removing the RewriteBase is necessary because of the error. Here, I also
just change the RewriteRule to:
RewriteRule .* /path_to_typo/index.php
The typo3-dir rules don't work now, they have to be changed to:

1) RewriteRule ^/path_to_typo/typo3/ - [L]
2) RewriteRule ^/path_to_typo/typo3 /path_to_typo/typo3/ [L]
  (or: "RewriteRule ^(/path_to_typo/typo3)$ $1/ [L]")

You can also see that I swapped the order of these two rules. I did that,
because rule 1) will handle almost all requests to the backend (including
global extensions). Rule 2) is only used if you type in the URL to the
backend manually and don't add a slash to it. It appeared that it DIDN'T
work if it was rewritten to /path_to_typo/typo3/index_re.php, but it DID
work if it was rewritten to just /path_to_typo/typo3/)

While we're at it: it might be a GOOD idea, to even change rule 1) to the
following:
RewriteRule
^/path_to_typo/(typo3temp|typo3|typo3conf|t3lib|tslib|fileadmin)/ - [L]

This way, a LOT of stat()-calls will be saved (to test if the
file/dir/symlink exist), so serverload and SPEED will be much better!
I tested this with very verbose rewrite-logging and it worked like a
charm...

##########################
I would like to propose the following file (only the rewrite-part shown, the
php-stuff works OK):

### Begin: Rewrite stuff ###

#######
# IMPORTANT: You have to change this file to fit your
# installation of TYPO3:
#
# You should change every occurance of TYPO3root/ to the
# location you have your website in. For example:
# If you have your website located at http://mysite.com/
# then your TYPO3root/ is just empty (remove 'TYPO3root/')
# If you have your website located at http://mysite.com/some/path/
# then your TYPO3root/ is some/path/ (search and replace)
#
# You can also use this configuration in your httpd.conf,
# but you'll have to use a somewhat different for some lines,
# see the comments.
# Using rewriting in your httpd.conf is much faster btw.
#######

# Enable URL rewriting
RewriteEngine On

# To assist in debugging rewriting, you could use these lines
# DON'T enable it for production!
# This will only work in httpd.conf, not in a .htaccess-file
#RewriteLog /var/log/apache/rewrite.log
#RewriteLogLevel 9

# Stop rewrite processing if the URL starts with one of the 'special'
# TYPO3-paths
# For httpd.conf, use:
# RewriteRule
^/TYPO3root/(typo3temp|typo3|typo3conf|t3lib|tslib|fileadmin)/ - [L]
RewriteRule ^(typo3temp|typo3|typo3conf|t3lib|tslib|fileadmin)/ - [L]

# Redirect http://mysite.com/typo3 to http://mysite.com/typo3/
# and stop the rewrite processing
# For httpd.conf, use:
# RewriteRule ^/TYPO3root/typo3$ /TYPO3root/typo3/ [L]
RewriteRule ^typo3$ typo3/ [L]

# If the file/directory/symlink does not exist => Redirect to index.php
# For httpd.conf, use:
# RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
# RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
# RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

# Main URL rewriting
# This stays the same for httpd.conf
RewriteRule .* /TYPO3root/index.php

### End: Rewrite stuff ###

I tested this with .htaccess and (modified as described) in my httpd.conf.

Grtz,
Martin






More information about the TYPO3-dev mailing list