Author |
|
nitesh.apte
Joined: 25 Aug 2010 Posts: 21 Location: India
|
Posted: Wed 25 Aug '10 20:45 Post subject: rewrite and $_GET |
|
|
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: 7373 Location: Germany, Next to Hamburg
|
Posted: Thu 26 Aug '10 16:06 Post subject: |
|
|
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
|
Posted: Thu 26 Aug '10 16:37 Post subject: |
|
|
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: 7373 Location: Germany, Next to Hamburg
|
Posted: Thu 26 Aug '10 16:47 Post subject: |
|
|
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
|
Posted: Thu 26 Aug '10 17:42 Post subject: |
|
|
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
|
Posted: Thu 26 Aug '10 20:02 Post subject: |
|
|
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
|
Posted: Thu 26 Aug '10 20:15 Post subject: |
|
|
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
|
Posted: Thu 26 Aug '10 20:34 Post subject: |
|
|
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: 7373 Location: Germany, Next to Hamburg
|
Posted: Fri 27 Aug '10 10:00 Post subject: |
|
|
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
|
Posted: Fri 27 Aug '10 10:32 Post subject: |
|
|
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: 7373 Location: Germany, Next to Hamburg
|
Posted: Fri 27 Aug '10 13:44 Post subject: |
|
|
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
|
Posted: Fri 27 Aug '10 14:19 Post subject: |
|
|
I will try this |
|
Back to top |
|
nitesh.apte
Joined: 25 Aug 2010 Posts: 21 Location: India
|
Posted: Fri 27 Aug '10 17:12 Post subject: |
|
|
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
|
Posted: Sat 28 Aug '10 12:57 Post subject: |
|
|
If you guys have time then let me know the solution. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
|
Back to top |
|
nitesh.apte
Joined: 25 Aug 2010 Posts: 21 Location: India
|
Posted: Sat 28 Aug '10 14:25 Post subject: |
|
|
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
|
Posted: Mon 30 Aug '10 11:35 Post subject: |
|
|
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: 7373 Location: Germany, Next to Hamburg
|
Posted: Mon 30 Aug '10 11:42 Post subject: |
|
|
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
|
Posted: Mon 30 Aug '10 12:09 Post subject: |
|
|
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: 7373 Location: Germany, Next to Hamburg
|
Posted: Mon 30 Aug '10 13:02 Post subject: |
|
|
QUERY_STRING in PHP or apache? |
|
Back to top |
|