Forum Moderators: phranque
here's my htaccess:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule (.*) fileadmin/scripts/do-redirect.php [C]
RewriteRule .* index.php [L]
The do-redirect isn't invoked at all. All non-existent URLs go directly to index.php.
How can I execute do-redirect.php before index.php?
Would the following be considered a chain?
RewriteBase /
RewriteRule ^typo3 - [L]
RewriteRule ^typo3$ typo3/index.php [L]
#non-www to www redirect for .htaccess
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) fileadmin/scripts/do-redirect.php [L]
#www rule: exclude static files
RewriteCond %{HTTP_HOST} www\.example\.com$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* fileadmin/scripts/do-redirect.php [L]
Would it be more clear and compact to manage both rules in one?
RewriteBase /
RewriteRule ^typo3 - [L]
RewriteRule ^typo3$ typo3/index.php [L]
#call do-redirect
RewriteRule .* fileadmin/scripts/do-redirect.php [L]
if (is_file("../.." . $uri)){
if ($non_www) {
page301('http://www.example.com' . $uri);
exit;
} else
exit;
} else
...
What is (or vis-a-vis)?
# If requested URL-path starts with "typo3", skip all following rules
RewriteRule ^typo3 - [L]
# If requested URL-path starts is exactly "typo3", rewrite to /typo3/index.php
RewriteRule ^typo3$ typo3/index.php [L]
Please indicate what you are trying to do with those rules.
I believe that "or vis-a-vis" was intended to mean "or something like that."
Caterham's point is that once you call a script, control never returns to the server config files (e.g. .htaccess). So, whatever script you invoke with your rules, it must generate the entire server response. So, either it must generate a redirect, or it must generate the requested page content. As suggested, the easiest way is probably to call do-redirect, and if no redirect is required, then do-redirect should include (read-in and execute) index.php.
Or simply merge the two scripts, and include the do-redirect logic in index.php itself.
Jim
Jim
#non-www to www [b]redirect[/b] for .htaccess
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$ RewriteRule (.*) fileadmin/scripts/do-redirect.php [L] This cannot possibly work. A redirect should contain both a host name in the target URL, and [R=301,L].
The code above is for an internal rewrite, and has nothing to do with www and non-www.
I am guessing that a line of code is missing, before that very last line.
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^typo3 - [L]
#script non-www to www redirect
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) fileadmin/scripts/do-redirect.php [L]
#script www redirect
#exclude static files like images, css, robots, javascript, …
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
#call index.php (TYPO3) where the do-redirect is included
RewriteRule .* index.php [L]
With regards to:
RewriteRule ^typo3 - [L]
RewriteRule ^typo3$ typo3/index.php [L]
The problem is that the exact URL-path "typo3" will match the first rule, so the second will never be executed.
[edited by: jdMorgan at 4:28 pm (utc) on Feb. 26, 2009]
[edit reason] example.com [/edit]