28, May 2012

modRewrite and php - webmaster forum

 
Webdigity webmaster forums
[ 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
Instabuck - The easy way to sell digital products online

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



« on: Jun 20, 2006, 11:54:31 am »

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 or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #1 on: Jun 20, 2006, 01: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...

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #2 on: Jun 20, 2006, 01: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 or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #3 on: Jun 20, 2006, 01: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" ?

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #4 on: Jun 20, 2006, 01:30:07 pm »

Quote
maybe the "RewriteBase" ?

It displays the same error

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #5 on: Jun 20, 2006, 01:56:05 pm »

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

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #6 on: Jun 20, 2006, 02: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 or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #7 on: Jun 20, 2006, 02:07:33 pm »

whats is the content of the query string?

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #8 on: Jun 20, 2006, 02:11:06 pm »

screen=index.php&screen=xxx

when you call /dir/xxx

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #9 on: Jun 20, 2006, 02: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...

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #10 on: Jun 20, 2006, 02: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 or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #11 on: Jun 20, 2006, 02:28:36 pm »

can you try my rule on a diff. server?

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

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

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #12 on: Jun 20, 2006, 02: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 or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #13 on: Jun 20, 2006, 02: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...

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #14 on: Jun 20, 2006, 02: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 or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #15 on: Jun 20, 2006, 02: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

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #16 on: Jun 21, 2006, 02: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 or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #17 on: Jun 21, 2006, 03: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?

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #18 on: Jun 21, 2006, 03: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 or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #19 on: Jun 21, 2006, 04: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

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....

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?
May 28, 2012, 10:49:43 am





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!






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