0

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?

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

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. What do you mean it will not work.. I actually tested this and it worked.
@nikic. Also software like Drupal also does the same.
0

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.

Comments

0

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

RewriteCond $0 !^index\.php$
RewriteRule .* index.php?args=$0 [QSA,B]

3 Comments

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.