php, mysql, mod_rewrite

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
daande
Forum Newbie
Posts: 3
Joined: Wed Jan 06, 2010 4:17 pm

php, mysql, mod_rewrite

Post by daande »

So lets say I would like to make a pretty url to have site.com/123 instead of site.com/index.php?i=123. I have the code to do this and it works. However, when you enter site.com/123 it goes to the page but the url in the address bar of the browser changes to site.com/index.php?i=123 instead of remaining at site.com/123. Does anyone know if it is possible to keep it as site.com/123 after the redirect?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: php, mysql, mod_rewrite

Post by Christopher »

Post "the code to do this" (rewrite rules?) and perhaps someone can help.
(#10850)
daande
Forum Newbie
Posts: 3
Joined: Wed Jan 06, 2010 4:17 pm

Re: php, mysql, mod_rewrite

Post by daande »

Here is the .htaccess file:

Code: Select all

 
RewriteEngine On
RewriteRule ^([A-Za-z0-9-]+)/?$ http://site.com/getimage.php?i=$1 [L]
 
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: php, mysql, mod_rewrite

Post by requinix »

By including the "http://site.com/" you're telling mod_rewrite to do an external redirect.
If you want everything to remain internal, get rid of it.
daande
Forum Newbie
Posts: 3
Joined: Wed Jan 06, 2010 4:17 pm

Re: php, mysql, mod_rewrite

Post by daande »

Problem fixed. Thank you very much!
Post Reply