Posted By
|
Message
|
 Jacob!
Registered 17/06/2011
Points 153
|
17th February, 2011 at 06:30:16 -
Hello!
First post here, but I'm pretty sure this is the right forum
Anyway, I have an index.php file that requests an image based on a parameter in teh url. However, this looks really ugly to the user. How would I go about using a rewrite to change something like
http://domain.com/405/
into
http://domain.com/index.php?param=405
Have you even been far as decided to use even go want to do look more like?
|
 Jon Lambert Administrator
Vaporware Master
Registered 19/12/2004
Points 8235
     
|
17th February, 2011 at 07:58:30 -
Surely you're not referring to $_GET[param] are you? In PHP, anything past the question mark can be accessed using $_GET[]. What you would do is put all your code in the index.php file and then in the php code you would use $_GET[param] to get that parameter in the url.
http://domain.com/index.php?param=450&other=party
Anything past the ? is a parameter, with & serving as the delimiter between parameters. A $_GET parameter has a name and a value, for the example above we have a parameter with name param and value 450, and a parameter with name other and value party. To echo it in php, you would say:
echo $_GET[param];
Which would display "450".
Edited by an Administrator
Sandwich Time!Whoo!
JoyCheck & KeyCheck Widgets
For easy implementation of customizable joystick and keyboard controls.
http://www.create-games.com/download.asp?id=8364
|
 Duncan Thelonious Dunc
Registered 18/05/2002
Points 552
|
17th February, 2011 at 13:29:19 -
Presumably you meant the other way around?
http://httpd.apache.org/docs/2.0/rewrite/
From long and varied experience, copypasted htaccess code is a poor substitute for actually knowing what you're doing. Which is why I use Wordpress
Edited by Duncan
n/a
|
 Jacob!
Registered 17/06/2011
Points 153
|
18th February, 2011 at 04:50:57 -
You could say the other way around, it depends on how you look at it. The system will take the /405/ and turn it into index.php?param=405.
Have you even been far as decided to use even go want to do look more like?
|
 UrbanMonk BRING BACK MITCH
Registered 07/07/2008
Points 49667
         
  
|
18th February, 2011 at 15:41:57 -
Umm, you could use mod rewrite to do that, but what's the point?
The first way looks nicer.
n/a
|
 Flava
Registered 30/07/2002
Points 684
   
|
18th February, 2011 at 16:17:44 -
He want's to do it the other way round..
So that when you visit /405/ it will show /index.php?param=405
RewriteRule ^/(\d+)/$ /index.php?param=$1 [PT]
RewriteRule ^/(\d+)$ /index.php?param=$1 [PT]
This is a signature. Have this one on me.
|
 Jacob!
Registered 17/06/2011
Points 153
|
19th February, 2011 at 03:24:53 -
I guess I'm not explaining myself very well. THe user goes to the site http://domain.com/405/. As far as the user is concerned, they are at domain.com/405/. The system internally reads domain.com/405 as domain.com/index.php?param=405, which allows me to access the parameter for content on the page, while the user only sees domain.com/405/.
Have you even been far as decided to use even go want to do look more like?
|
 Cecilectomy noPE
Registered 19/03/2005
Points 305
         
|
19th February, 2011 at 03:50:15 -
use a uri class
the codeigniter php application framework has one built in for that
Edited by Cecilectomy
n/a
|
 Jacob!
Registered 17/06/2011
Points 153
|
19th February, 2011 at 20:42:58 -
There has to be an easier way than using a whole new PHP framework. It's really a simple site...
Have you even been far as decided to use even go want to do look more like?
|
 Cecilectomy noPE
Registered 19/03/2005
Points 305
         
|
21st February, 2011 at 04:42:53 -
i didnt say use a whole new framework. i said use a uri class, and that codeigniter has one built in. you can google 'php uri class' and get a ton of entries on the matter. its not that hard.
n/a
|
 Flava
Registered 30/07/2002
Points 684
   
|
21st February, 2011 at 06:28:52 -
Originally Posted by Jacob! There has to be an easier way than using a whole new PHP framework. It's really a simple site...
Did you try what I gave you? Should pretty much do exactly what you want..
Edited by Flava
This is a signature. Have this one on me.
|
 Jacob!
Registered 17/06/2011
Points 153
|
24th February, 2011 at 04:20:03 -
No, it doesn't.
RewriteEngine on
RewriteRule ^/(\d+)/$ /index.php?comic=$1 [PT]
RewriteRule ^/(\d+)$ /index.php?comic=$1 [PT]
is the full .htaccess file.
Working properly,
http://comic.jacobpariseau.com/0/ should be the same as
http://comic.jacobpariseau.com/index.php?comic=0
Have you even been far as decided to use even go want to do look more like?
|
 Jacob!
Registered 17/06/2011
Points 153
|
28th February, 2011 at 20:26:07 -
Ah, I looked into some of the syntax for this and I see a few things wrong. /d would would except there isn't a directory there, and although !/d might work in theory, I could just use numbers instead.
RewriteEngine on
RewriteRule ^([0-9]+)/?$ /index.php?comic=$1
RewriteRule ^([0-9]+)$ /index.php?comic=$1
solved it for me. Thanks anyway!
Have you even been far as decided to use even go want to do look more like?
|
|
|