Why does .htaccess only receive index.php as input
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开发者_StackOverflow社区 have the args variable be "lots/of/bogey". Any ideas what I'm doing wrong?
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
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
.
You'll have at least to exclude index.php from the redirect:
RewriteCond $0 !^index\.php$
RewriteRule .* index.php?args=$0 [QSA,B]
精彩评论