Denver William
Denver William

Reputation: 413

HTACCESS Works, But php $_GET Does Not

I have read through almost every post regarding this issue, and nothing seems to work.

I have successfully rewritten the below code, and it works just fine. The .htaccess file is in the /~user/business/ folder. I use RewriteRule ^index/([0-9]+)/?$ /index.php?id=$1 [QSA,PT] while accessing http://localhost/~user/business/index/155/. However, when I try to get the variable in php, it returns nothing. The rewrite works as it does load index.php, but no get variables at all.

My main goal, I want to access the id from the code above, but nothing shows up. <?php echo $_GET['id']; ?> Even when I try this print_r($_GET); the array of all get variables, it returns an empty array. I also do not want to append the query to the end of url at all.

Lots of posts have answers that work according to responses, and even when I copy them word for word, letter for letter, changing the directories and addresses, nothing seems to work.

I am using Apache 2, set up on a MAC as localhost. Is there something wrong, maybe in the php.ini file?

Upvotes: 1

Views: 552

Answers (1)

Denver William
Denver William

Reputation: 413

After many times trying, as much as reconfiguring the entire virtual host setup on my mac, I realized that it was a very simple error once I realized it, and it had nothing at all to do with my .htaccess file.

My file name was index.php and my rewrite was RewriteRule ^index/([a-zA-Z0-9_-]+)/ index.php?id=$1 [NC,L] and for some reason, it will not let me use ^index if there is a file called index.php. I can name ^index to ^page or ^blue or anything else but not ^index and it will work fine.

What I realized was that my /index.php page can be loaded simply by typing /index. And therefore, was not actually a redirect, it was the stand alone page.

In order to fix this I had to add a few lines of code to my vhost.conf or my user.conf file under <Directory "/Users/User/Sites"> file using the terminal.

sudo nano /private/etc/apache2/extra/httpd-vhosts.conf

and in this, the code I had to removed MultiViews from the options.

<Directory "/Users/User/Sites">
    Options Indexes FollowSymLinks SymLinksifOwnerMatch MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

so it now looks like this

<Directory "/Users/User/Sites">
    Options Indexes FollowSymLinks SymLinksifOwnerMatch
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

Once I did so, /index.php page can no longer be loaded by typing /index. And therefore, I could use the code I originally used in my .htaccess file. And all is solved in paradise. It took a lot of very hard digging and one major headache.

Thanks for your help guys.

Upvotes: 4

Related Questions