24, July 2008

modRewrite and php - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web hosting talk  >  Configuring your server  >  Apache web server
Topic: modRewrite and php
« previous next »
Pages: [1] Print

Author Topic: modRewrite and php  (Read 2107 times)
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 7975
40807 credits
Members referred : 3



« on: Jun 20, 2006, 12:54:31 PM »

Here is a problem I have.

I use the above modrewrite rule to redirect subdirectories of a directory to a php script :

Code:
RewriteEngine on
Options +FollowSymlinks
RewriteBase /
RewriteRule dir/(.*)$  dir/index.php?screen=$1 [QSA,L]

So it will redirect /dir/xxx to /dir/index.php?screen=xxx right?

The problem is that php can't 'see' the screen in $_GET or $_REQUEST, so the only way to see what it passes is through $QUERY_STRING which does not helps much as it returns this :

Code:
screen=index.php&screen=xxx

Can you help me with this? Any response will be deeply appreciated.

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6280
38506 credits
Members referred : 374


It's time to use PHP5!


« Reply #1 on: Jun 20, 2006, 02:17:03 PM »

I think you need something like:

Code:
rewriteCond %{REQUEST_URI} ^/links/([a-z\-]+)
RewriteRule .* /links.php?cat=%1 [L]

I know I didn't used your vars but the condition works the same...


Last blog : 4th of July Lottery from TemplateMonster.com
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 7975
40807 credits
Members referred : 3



« Reply #2 on: Jun 20, 2006, 02:27:30 PM »

Thanks for the reply, but unfortunatelly that returns a 500 error (misconfiguration)

Propably this is because I use other rewrite rules also.

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6280
38506 credits
Members referred : 374


It's time to use PHP5!


« Reply #3 on: Jun 20, 2006, 02:28:41 PM »

Thanks for the reply, but unfortunatelly that returns a 500 error (misconfiguration)

Propably this is because I use other rewrite rules also.

maybe the "RewriteBase" ?


Last blog : 4th of July Lottery from TemplateMonster.com
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 7975
40807 credits
Members referred : 3



« Reply #4 on: Jun 20, 2006, 02:30:07 PM »

Quote
maybe the "RewriteBase" ?

It displays the same error

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6280
38506 credits
Members referred : 374


It's time to use PHP5!


« Reply #5 on: Jun 20, 2006, 02:56:05 PM »

what is the current rule you're using (according my suggestion)?


Last blog : 4th of July Lottery from TemplateMonster.com
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 7975
40807 credits
Members referred : 3



« Reply #6 on: Jun 20, 2006, 03:02:37 PM »

I used this (that doesn't works) :

Code:
RewriteCond %{REQUEST_URI} ^/dir/([a-z\-]+)
RewriteRule .* /dir/index.php?screen=%1 [L]

And I have this that almost works (it doesn't pass the $_GET variable, but it has the right $QUERY_STRING ):

Code:
RewriteRule dir/(.*)$  dir/index.php?screen=$1 [QSA,L]

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6280
38506 credits
Members referred : 374


It's time to use PHP5!


« Reply #7 on: Jun 20, 2006, 03:07:33 PM »

whats is the content of the query string?


Last blog : 4th of July Lottery from TemplateMonster.com
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 7975
40807 credits
Members referred : 3



« Reply #8 on: Jun 20, 2006, 03:11:06 PM »

screen=index.php&screen=xxx

when you call /dir/xxx

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6280
38506 credits
Members referred : 374


It's time to use PHP5!


« Reply #9 on: Jun 20, 2006, 03:15:04 PM »

screen=index.php&screen=xxx

when you call /dir/xxx
that's why you need to store the value uf screen into an variable or you need to cut this new QS into smaller pieces first...

Its strange that you get this 500 error, I use this kind of patterns all the time...


Last blog : 4th of July Lottery from TemplateMonster.com
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 7975
40807 credits
Members referred : 3



« Reply #10 on: Jun 20, 2006, 03:21:13 PM »

Quote
that's why you need to store the value uf screen into an variable or you need to cut this new QS into smaller pieces first...

That's what I do now, but it is very silly to do that ($_GET['action'] = substr(strstr(substr(strstr($QUERY_STRING,'='),1),'='),1)Wink

but I am sure there should be a cleaner way to do this Smiley

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6280
38506 credits
Members referred : 374


It's time to use PHP5!


« Reply #11 on: Jun 20, 2006, 03:28:36 PM »

can you try my rule on a diff. server?

its actually from this site: http://www.buitenspelen.eu/links/speelgoed Visit through proxy

my get var is "links" and the value is "speelgoed"


Last blog : 4th of July Lottery from TemplateMonster.com
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 7975
40807 credits
Members referred : 3



« Reply #12 on: Jun 20, 2006, 03:31:37 PM »

Yeah all those tests was in a windows development server. I will try to run those in the linux development server, and then in the production server, to see if there is a change.

I will keep you posted. And thanks for the help so far Smiley

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6280
38506 credits
Members referred : 374


It's time to use PHP5!


« Reply #13 on: Jun 20, 2006, 03:36:51 PM »

Yeah all those tests was in a windows development server. I will try to run those in the linux development server, and then in the production server, to see if there is a change.

I will keep you posted. And thanks for the help so far Smiley

hm... it works on my local WAMP (win XP, apache 2, mysql 4.1, php 5.1) configuration too are you using apache as a module?

EDIT: but I remember that I got this error on CGI apache configs...


Last blog : 4th of July Lottery from TemplateMonster.com
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 7975
40807 credits
Members referred : 3



« Reply #14 on: Jun 20, 2006, 03:40:12 PM »

Quote
are you using apache as a module?

How can I see that? Do you mean I use php as a module? (I don't)

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6280
38506 credits
Members referred : 374


It's time to use PHP5!


« Reply #15 on: Jun 20, 2006, 03:42:44 PM »

Quote
are you using apache as a module?

How can I see that? Do you mean I use php as a module? (I don't)
yes of cource php as a module  Embarrassed


Last blog : 4th of July Lottery from TemplateMonster.com
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 7975
40807 credits
Members referred : 3



« Reply #16 on: Jun 21, 2006, 03:59:53 PM »

I finally found it.

The right one is :

Code:
RewriteBase /dir
RewriteRule ^/?(.*)$ index.php?action=$1 [L,QSA]

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6280
38506 credits
Members referred : 374


It's time to use PHP5!


« Reply #17 on: Jun 21, 2006, 04:37:08 PM »

I finally found it.

The right one is :

Code:
RewriteBase /dir
RewriteRule ^/?(.*)$ index.php?action=$1 [L,QSA]

a possible leading slash?


Last blog : 4th of July Lottery from TemplateMonster.com
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 7975
40807 credits
Members referred : 3



« Reply #18 on: Jun 21, 2006, 04:42:40 PM »

I don't really understand, but I am happy that it works. Smiley

The bad thing with modrewrite is that you can't really debug or see the results of what you are doing. It is like programming in assembly lol Tongue

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6280
38506 credits
Members referred : 374


It's time to use PHP5!


« Reply #19 on: Jun 21, 2006, 05:02:03 PM »

I don't really understand, but I am happy that it works. Smiley

The bad thing with modrewrite is that you can't really debug or see the results of what you are doing. It is like programming in assembly lol Tongue
yes you can if you have acces to the mod_rewrite log... but this is not the "easy to understand" log report


Last blog : 4th of July Lottery from TemplateMonster.com
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=2939
Tags : php mysql apache programming linux Bookmark this thread : Digg Del.icio.us Dzone more....

Topic sponsors:
Get a permanent link here for $1.99!


Pages: [1] Print 
Webdigity Webmaster Forums  >  Web hosting talk  >  Configuring your server  >  Apache web server
Topic: modRewrite and php
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Jul 24, 2008, 05:07:43 PM





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!


Forum Statistics
Total Posts: 35.717
Total Topics: 7.379
Total Members: 3.710
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: prolist

25 Guests, 4 Users online :

12 users online today:



Readers

Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2008 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.