tags:

views:

36

answers:

3

I have added a .htaccess file to my root folder, and i wanted everything written after the / to be sent to the index.php file as get data.

My root path looks like this http://www.site.com/folder/ and my .htaccess is located in the folder directory together with index.php

This is my .htaccess file:

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) index.php?args=$1

Now, what ever i write behind folder/ in my url, args is "index.php". So when i visit www.site.com/folder/lots/of/bogey the args variable is "index.php"

My goal is obviously to have the args variable be "lots/of/bogey". Any ideas what I'm doing wrong?

A: 

I think that's because after executing the RewriteRule and getting index.php?args=... the RewriteRule gets called again. Now index.php is your filename, so it get's passed as args. After this mod_rewrite aborts due to recursion. To fix this, add a RewriteCond which enures the file isn't index.php.

nikic
A: 

You'll have at least to exclude index.php from the redirect:

RewriteCond $0 !^index\.php$
RewriteRule .* index.php?args=$0 [QSA,B]
Artefacto
It would be better for my image tags if i could exclude any input containing ".". Could you show me how to do that?
Codemonkey
@Code Substitute the rewritecond I gave for `RewriteCond $0 !\.`. Since "index.php" has a dot, this catches the case of index.php too
Artefacto
RewriteCond $0 !\. is what i did, and it worked wonders. Thanks
Codemonkey
A: 

You don't need a RewriteCond. The following will work:

RewriteRule ^(.*)$ index.php?args=$1 [L,QSA]

The L makes it stop matching rewrite rules, and QSA is for appending to query string in a rewrite rule. Refer to mod_rewrite

grom
Could you explain what the flags do? thx
Codemonkey
No, this will not work. Even though it is the [L]ast RewriteRule in this pass, mod_rewrite will call itself again with the new, rewritten filname - which will be index.php!
nikic
@nikic. What do you mean it will not work.. I actually tested this and it worked.
grom
@nikic. Also software like Drupal also does the same.
grom