0

I have this .htaccess below, with my rule, my index.php is my default, is where I acess all, where I want to do my navigation, this index also recover variable url:

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1

Then I have my function getHome() to handle url, for now Im just echo my $url, that was supposed to get the value passed by url:

function getHome(){
    $url = $_GET['url'];
    echo $url;
}

Than I have my index.php where Im calling my getHome(), and for now Im testing, passing some values on my url.

But when I pass some random values into my url, I'm getting always "Object not found!....Error 404"

But I wanted to echo my values that I passed in the URL.

Do you see what am I doing wrong?

Update:

Im had a <? instread of <?php in my code, and now Im having an error:

Notice: Undefined index: url in $url = $_GET['url'];

I update my function to:

$url = isset($_GET['url']);

And now I dont have undefined index error, but I have the same error before, when I pass some random values to my URL, I always get my "Object not found...Error 404".

OzzC
  • 815
  • 4
  • 20
  • 36

2 Answers2

2

Check if mod_rewrite is enabled, and also check if the webserver configuration allows to use .htaccess files - see http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride for a detailed explanation.

  • Thanks for your answer, but the mod_rewrite is enabled, it was the first thing I did. But now I update my question, because I was here with my open php tag wrong, and now Im having an undefined index error! – OzzC May 25 '14 at 17:35
  • it's not being set so therefore your config must be wrong. i've tested the same .htaccess and so has @hyubs so it's something on your end with apache configuration. – Ruby May 25 '14 at 17:38
  • Im using xampp. I just need to enable AllowOverride All and mod_rewrite right? – OzzC May 25 '14 at 17:42
1

This should be working, but as an alternative you could also use:

$url = $_SERVER['REQUEST_URI'];

Then you would not have to check if anything is set or pass a query variable in your rewrite rule.

jeroen
  • 91,079
  • 21
  • 114
  • 132