logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: rewrite and $_GET Page 1, 2  Next
Author
nitesh.apte



Joined: 25 Aug 2010
Posts: 21
Location: India

PostPosted: Wed 25 Aug '10 20:45    Post subject: rewrite and $_GET Reply with quote

I have a very strange problem. First of all, this is the content of .htaccess file that I am using for my project:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /myproject/
RewriteRule ^user/([^/]+)/([^/]+) user.php?user=$1&field=$2 [NC]
RewriteRule ^profile/([^/]+)/([^/]+) profile.php?profile=$1&field=$2 [NC]
RewriteRule ^user/(.*) user.php?user=$1
RewriteRule ^invite/(.*) invite.php?invite=$1
RewriteRule ^activate/(.*) activate.php?activate=$1
RewriteRule ^profile/(.*) profile.php?profile=$1
RewriteRule ^captcha/captcha lib/captcha/securimage_show.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

Problem is:
1) I am unable to get any values in $_GET.
2) I have deleted this file but things are still working. Means, user.php is still working as /user/. I do restarted the server.

Any help will be appreciated.

Modnote: Gave the topic a better title
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7372
Location: Germany, Next to Hamburg

PostPosted: Thu 26 Aug '10 16:06    Post subject: Reply with quote

If $_GET isn't working you might try pathinfo

Code:

$arguments = explode('/',
   $_SERVER['PATH_INFO'] );
echo '<pre>';
print_r($arguments);
echo '</pre>';


Is than anything printed?
Back to top
nitesh.apte



Joined: 25 Aug 2010
Posts: 21
Location: India

PostPosted: Thu 26 Aug '10 16:37    Post subject: Reply with quote

Yes. I am getting the required value in $arguments[1]. But the thing is why I am not getting anything in $_GET. Also, how is this working when I have deleted .htaccess file. Can you help me please?

I am using Ubuntu with standard apache2 installation.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7372
Location: Germany, Next to Hamburg

PostPosted: Thu 26 Aug '10 16:47    Post subject: Reply with quote

The questions is whys using one time rewriting and not on the other time? The $_GET array contains all variables from the URL. So if there is a parameter like ?var1=bla&var2=bla-also the $_GET isn't filled.
you need to set the pass through flag "PT" for the rewrite
rules. Than you can use alway $_GET
See also "pass through" in
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
Back to top
nitesh.apte



Joined: 25 Aug 2010
Posts: 21
Location: India

PostPosted: Thu 26 Aug '10 17:42    Post subject: Reply with quote

I am going to check the link you have posted.

Thing is, I was developing a project in XAMPP. But, somehow my PC got corrupted so I re-installed Ubuntu, nut, this time I did standard installation of apache2. Then, I faced the problem posted above. I was not getting anything in $_GET. Just to see what happens, I deleted the .htaccess file and restarted apache2. But user.php is still working as /user/.

So, the main thing is that how is it working after deleting the .htaccess file. And in either of the case, $_GET is not working.

Can you tell me why it is happening after deleting .htaccess file. Any help will be appreciated as my project is struck in between.
Back to top
nitesh.apte



Joined: 25 Aug 2010
Posts: 21
Location: India

PostPosted: Thu 26 Aug '10 20:02    Post subject: Reply with quote

Ok.....Now I have deleted rewrite.load from mod-enabled folder. But it is still working. So, can it a problem of installation of apache?
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Thu 26 Aug '10 20:15    Post subject: Reply with quote

I'm not saying this is the problem, I'm just throwing it out there.

I have found that Apache on occasion has a annoying little trick. You make a change in your config, restart the server and your changes do not show up.

What seems to be happening is Apache runs a test on the config before actually going through the restart. If there is a problem, Apache appears to restart, but actually doesn't.

I've gotten used to this and know that if changes do not take effect, it's time to start looking at the error and Windows Event logs. I always find "Syntax error on line ### of somefile.conf .... bla bla bla"

So, I'd say check your error logs after a restart if changes seem to not take effect.
Back to top
nitesh.apte



Joined: 25 Aug 2010
Posts: 21
Location: India

PostPosted: Thu 26 Aug '10 20:34    Post subject: Reply with quote

This is logged in error.log file:
[Thu Aug 26 23:57:09 2010] [notice] Apache/2.2.14 (Ubuntu) PHP/5.3.2-1ubuntu4.2 with Suhosin-Patch configured -- resuming normal operations.

So, it means apache does restart. Please guys help me out here as my project is struck in between.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7372
Location: Germany, Next to Hamburg

PostPosted: Fri 27 Aug '10 10:00    Post subject: Reply with quote

glsmith wrote:

What seems to be happening is Apache runs a test on the config before actually going through the restart. If there is a problem, Apache appears to restart, but actually doesn't.


That's why to use the -S switch before do the real restart

Code:

sudo apache2ctl -S
sudo apache2ctl graceful
Back to top
nitesh.apte



Joined: 25 Aug 2010
Posts: 21
Location: India

PostPosted: Fri 27 Aug '10 10:32    Post subject: Reply with quote

I did that. No effect. Still user.php is working as /user/ though there is no .htaccess. And I have set AllowOverride None.

Could this be apache installation problem?
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7372
Location: Germany, Next to Hamburg

PostPosted: Fri 27 Aug '10 13:44    Post subject: Reply with quote

Yes, it is perfectly legal to have that extra /anyText after the filename part of the URI.
That extra /anyText part of the http://localhost/test.html/anyText URL is called PATH_INFO.

It should be rejected by default when Apache is serving static files.
If you have a filter or a cgi handler, it is accepted by default.

Take a look at the AcceptPathInfo Directive for more options about allowing or disallowing this.
Back to top
nitesh.apte



Joined: 25 Aug 2010
Posts: 21
Location: India

PostPosted: Fri 27 Aug '10 14:19    Post subject: Reply with quote

I will try this
Back to top
nitesh.apte



Joined: 25 Aug 2010
Posts: 21
Location: India

PostPosted: Fri 27 Aug '10 17:12    Post subject: Reply with quote

Ok. Now I am using the .htaccess file. How can get the values in $_GET because I have already implemented $_GET at several places. Any help.
Back to top
nitesh.apte



Joined: 25 Aug 2010
Posts: 21
Location: India

PostPosted: Sat 28 Aug '10 12:57    Post subject: Reply with quote

If you guys have time then let me know the solution.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7372
Location: Germany, Next to Hamburg

PostPosted: Sat 28 Aug '10 14:18    Post subject: Reply with quote

I forgot the query string append option (QSA) Embarassed

So e.g. to one of your rewrite rules

Code:

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


Please also consult the docs http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule
Back to top
nitesh.apte



Joined: 25 Aug 2010
Posts: 21
Location: India

PostPosted: Sat 28 Aug '10 14:25    Post subject: Reply with quote

I did changed my .htaccess and this time I put [QSA,L]. But no effect.
But it was working fine without [QSA,L] in XAMPP. I don't know where I am messing up the things.

I am checking the link you have posted.
Back to top
nitesh.apte



Joined: 25 Aug 2010
Posts: 21
Location: India

PostPosted: Mon 30 Aug '10 11:35    Post subject: Reply with quote

Thanks for your help guys. But unfortunately, I was not able to configure Apache to meet my requirement as I am not an Apache expert. I have switched back to XAMPP.

Thanks anyways.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7372
Location: Germany, Next to Hamburg

PostPosted: Mon 30 Aug '10 11:42    Post subject: Reply with quote

You may figure out what is the difference from XAMPP to your apache. Would be nice to know.
Back to top
nitesh.apte



Joined: 25 Aug 2010
Posts: 21
Location: India

PostPosted: Mon 30 Aug '10 12:09    Post subject: Reply with quote

I did. Only one thing I found out that in XAMPP, value in QUERY_STRING was coming but not in standard installation. But I don't know how and why. Do I need to enable any module in standard installation?
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7372
Location: Germany, Next to Hamburg

PostPosted: Mon 30 Aug '10 13:02    Post subject: Reply with quote

QUERY_STRING in PHP or apache?
Back to top


Reply to topic   Topic: rewrite and $_GET View previous topic :: View next topic
Post new topic   Forum Index -> Apache Page 1, 2  Next