Forum Moderators: phranque
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^/$ /index.php?module=welcome [L,QSA]
#
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/([^/]*)$ /index.php?module=$1 [L,QSA]
#
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/([^/]*)/([^/]*)$ /index.php?module=$1&class=$2 [L,QSA]
#
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/([^/]*)/([^/]*)/([^/]*).html$ \
/index.php?module=$1&class=$2&event=$3 [L,QSA]
Any ideas about what I'm doing wrong here? It's giving me 404s.
.htaccess is a "per-directory" configuration file. Therefore the path to the current directory --in this case "/"-- is removed from the URL-path "seen" by RewriteRule.
It should not be necessary to include "%{DOCUMENT_ROOT}/" when using %{REQUEST_FILENAME}
The "([^/]*)" subpatterns are open to a common error: the occurrence of multiple consecutive slashes. When these occur (mostly due to typing errors), Apache ignores them, but your rules will behave differently. To prevent this problem, I'd suggest using "([^/]+)" instead.
The processing of the final subpattern in the last rule can be sped up by telling the regex parser to quit processing that subpattern if it finds a period in a request that will subsequently match, as well as quitting when it find a slash in a request which will not subsequently match (as you've already done).
Your last rule also contains an unescaped literal period.
So, rolling this all together and using your last rule as an example, I'd suggest:
RewriteCond [b]%{REQUEST_FILENAME}[/b] !-d
RewriteCond [b]%{REQUEST_FILENAME}[/b] !-f
RewriteRule [b]^([^[/b]/][b]+)[/b]/([^/][b]+)/([^/.]+)\.h[/b]tml$ /index.php?module=$1&class=$2&event=$3 [L,QSA]
Your first rule is of a form not usually needed. This function is typically implemented using the DirectoryIndex directive:
DirectoryIndex /index.php?module=welcome