homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

redirect gives unexpected results

 2:57 pm on May 17, 2010 (gmt 0)

My htaccess file
Options +FollowSymLinks

RewriteEngine On
RewriteBase /help/

RewriteRule ^inloggen$help.php?topic=inloggen
RewriteRule ^(.*)$ help.php?topic=$1

My help.php
<? print_r($_REQUEST); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

I would like to redirect from domein.com/help/anything to domain.com/help/topic=anything

$_REQUEST['topic'] contains 'inloggen' in the first case, but if i use any other address, like domain.com/help/anything its content is help.php instead of anything

I cannot figure out why. Could yo please help me?



 3:07 pm on May 17, 2010 (gmt 0)

Bad syntax.
No [L] flags.
2nd rule rewrites *anything* to help.php, including help.php itself (and thus creates a loop).

Suggested changes:

Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine on
RewriteRule ^help/inloggen$ help/help.php?topic=inloggen [L]
RewriteCond $1 !^help\.php$ [L]
RewriteRule ^help/(.*)$ help/help.php?topic=$1 [L]

Note that this is NOT a redirect, and it should not be a redirect. It is an internal rewrite -- a URL-to-server-filepath translation.



 6:36 am on May 18, 2010 (gmt 0)

Thanks jdMorgan for responding.

Your reply however, pasted and added to my .htaccess gives me a 500 error. So i looked for invisible characters but could not find any.
Deleting the [L] after the condition removed the error, but gave me a 404, both in my help folder as well as in the base folder.

With your suggesion, however, i got it working :-)

Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine on
RewriteBase /help/
RewriteCond $1 !^help\.php$
RewriteRule ^(.*)$ help.php?topic=$1 [L]

Thanks a lot for putting me in the right direction!


 8:10 am on May 18, 2010 (gmt 0)

RewriteBase possibly has something to do with it, I'd guess.

However, you might need to remove
+FollowSymLinks or one of the other options.

Don't remove the [L]. The [L] is important.


 8:19 am on May 18, 2010 (gmt 0)

Thanks g1smd

I can understand the [L] is important, as it means Last.
However, if i put an L after a condition, doesn't that mean that interpreting the condition is the last thing that is done by the server? or will the rule following the condition be executed anyway?

with an example, in
RewriteCond $1 !^help\.php$
RewriteRule ^(.*)$ help.php?topic=$1 [L]
the rewriterul is executed, whereas in
RewriteCond $1 !^help\.php$ [L]
RewriteRule ^(.*)$ help.php?topic=$1 [L]
it is not executed? Or am i wrong. In that case, please enlighten me.

I need mod_rewrite in almost every site i make, so i am happy to learn :-)

Thanks a lot


 4:23 pm on May 18, 2010 (gmt 0)

Do not attempt to use an [L] flag on a RewriteCond -- That makes no sense, and is invalid.

The [L] flag on a RewriteRule terminates this pass of mod_rewrite processing only if this rule is invoked.

However, in .htaccess context, mod_rewrite processing is re-started from the top after any rule is invoked, and will continue to be re-started until a complete pass is made through all rules with none being invoked.

Therefore, [L] must be viewed as an 'efficiency and precedence-control' mechanism only -- It is not a literal "stop here and do nothing else" command in the .htaccess context.

This explains several things -- For example, it explains why rewrite looping must be explicitly prevented in .htaccess.

There is an awful lot of detail involved in the successful use of mod_rewrite, and all details are important... And even if the code itself is correct, many fail to also consider the effect of the code on search engines. This is not at all a simple subject.



 4:47 pm on May 18, 2010 (gmt 0)

Thank you Jim

It gave me a bit more insight into the voodoo :-)


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved