Posted By
|
Message
|
![](images/avatars/1.gif) 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?
|
![](http://www.jonhlambert.com/redcapsquare.png) Jon Lambert Administrator
Vaporware Master
Registered 19/12/2004
Points 8235
![VIP Member VIP Member](tags/vipbadge.png) ![Wii Owner Wii Owner](tags/Wiiowner.png) ![TDC Chat Super User TDC Chat Super User](tags/../uploads/tdchatbadge.png) ![I am an April Fool I am an April Fool](tags/fool.png) ![SSBB 3265-4741-0937 SSBB 3265-4741-0937](tags/../uploads/ssbb.png) ![ACCF 3051-1173-8012 ACCF 3051-1173-8012](tags/../uploads/accf.png)
|
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
|
![](http://i.imgur.com/gwJMg.gif) 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
|
![](images/avatars/1.gif) 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?
|
![](https://i.imgur.com/sLVzJGn.gif) UrbanMonk BRING BACK MITCH
Registered 07/07/2008
Points 49667
![Has Donated, Thank You! Has Donated, Thank You!](tags/coins.gif) ![Little Pirate! Little Pirate!](tags/lilpirate.png) ![ARGH Sign ARGH Sign](tags/argh.gif) ![Kliktober Special Award Tag Kliktober Special Award Tag](tags/scarytag2.png) ![Picture Me This Round 33 Winner! Picture Me This Round 33 Winner!](tags/picturemethisbandit.gif) ![The Outlaw! The Outlaw!](tags//r2.gif) ![VIP Member VIP Member](tags/vipbadge.png) ![Hasslevania 2! Hasslevania 2!](tags/r1.gif) ![I am an April Fool I am an April Fool](tags/fool.png) ![Kitty Kitty](tags/../uploads/cat.gif)
![Picture Me This Round 32 Winner! Picture Me This Round 32 Winner!](tags/picturemethisbandit.gif) ![Picture Me This Round 42 Winner! Picture Me This Round 42 Winner!](tags/picturemethisbandit.gif) ![Picture Me This Round 44 Winner! Picture Me This Round 44 Winner!](tags/picturemethisbandit.gif)
|
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
|
![](http://www.create-games.com/images/drinkmilk.png) Flava
Registered 30/07/2002
Points 684
![Has Donated, Thank You! Has Donated, Thank You!](tags/coins.gif) ![Code Monkey Code Monkey](tags/monkey.gif) ![VIP Member VIP Member](tags/vipbadge.png) ![The Cake is a Lie The Cake is a Lie](tags/cakeisalie.png)
|
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.
|
![](images/avatars/1.gif) 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?
|
![](images/avatars/5.gif) Cecilectomy noPE
Registered 19/03/2005
Points 305
![Has Donated, Thank You! Has Donated, Thank You!](tags/coins.gif) ![VIP Member VIP Member](tags/vipbadge.png) ![Weekly Picture Me This Winner! Weekly Picture Me This Winner!](tags/picturemethisbandit.gif) ![Cardboard Box Cardboard Box](tags/cardboardbox.gif) ![Ghostbuster! Ghostbuster!](tags/ghostbuster.gif) ![Pokemon Ball! Pokemon Ball!](tags/pokeball.gif) ![Computer Computer](tags/computer.png) ![Box Red Box Red](tags/box-red.gif) ![Santa Hat Santa Hat](tags/santa-hat.gif) ![Snowman Snowman](tags/Snowman.gif)
|
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
|
![](images/avatars/1.gif) 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?
|
![](images/avatars/5.gif) Cecilectomy noPE
Registered 19/03/2005
Points 305
![Has Donated, Thank You! Has Donated, Thank You!](tags/coins.gif) ![VIP Member VIP Member](tags/vipbadge.png) ![Weekly Picture Me This Winner! Weekly Picture Me This Winner!](tags/picturemethisbandit.gif) ![Cardboard Box Cardboard Box](tags/cardboardbox.gif) ![Ghostbuster! Ghostbuster!](tags/ghostbuster.gif) ![Pokemon Ball! Pokemon Ball!](tags/pokeball.gif) ![Computer Computer](tags/computer.png) ![Box Red Box Red](tags/box-red.gif) ![Santa Hat Santa Hat](tags/santa-hat.gif) ![Snowman Snowman](tags/Snowman.gif)
|
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
|
![](http://www.create-games.com/images/drinkmilk.png) Flava
Registered 30/07/2002
Points 684
![Has Donated, Thank You! Has Donated, Thank You!](tags/coins.gif) ![Code Monkey Code Monkey](tags/monkey.gif) ![VIP Member VIP Member](tags/vipbadge.png) ![The Cake is a Lie The Cake is a Lie](tags/cakeisalie.png)
|
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.
|
![](images/avatars/1.gif) 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?
|
![](images/avatars/1.gif) 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?
|
|
|