What is the best way to learn to use URL rewrite using php and MySQL?

Glenn

Member
I want it to read the database for an article and have a field with the new url.

Where can I read a step by step way to do this?
 

chrishirst

Well-Known Member
Staff member
I want it to read the database for an article and have a field with the new url.

EXACTLY as you would with 'dynamic' URLs

site.tld/this-is-a-long-url/ only serves the content from site.tld?doc=54321 it does not change the fundamental operation of code and database interaction.
 

Glenn

Member
EXACTLY as you would with 'dynamic' URLs

site.tld/this-is-a-long-url/ only serves the content from site.tld?doc=54321 it does not change the fundamental operation of code and database interaction.

Ok, so where is a good step by step explanation of how to do it?
 

Glenn

Member
Threads started by Glenn

You ever posted any answers to anything? I would have thought by now that after asking that many questions you would be immensely knowledgeable...

A time or two. I'd like to get to that point but I'm really not using it enough to be really good at it. I have a lot of good ideas, just not the time to follow through with them fully because of my full time job so what I learn is not real strong due to lack of using it.
 

ronaldroe

Super Moderator
Staff member
I have a lot of good ideas, just not the time to follow through with them fully because of my full time job so what I learn is not real strong due to lack of using it.

Don't let that stop you. You just have to make time. Trust me, I've been doing it for years. Sure, I can't dedicate as much time as others who do it full time, but I work it in. You can too.
 

Glenn

Member
Don't let that stop you. You just have to make time. Trust me, I've been doing it for years. Sure, I can't dedicate as much time as others who do it full time, but I work it in. You can too.

Yes, I'm a full time teacher. What I'm saying that I don't have time for is to work on my ideas so I don't practice the web design that I learn. Each time I work on it, I have to go back and read up on what I'm doing. Most of the time now, I know enough to search for what I need. Or at least to ask the right questions.
 

Glenn

Member
ok, I have read a lot and have made some changes.


I have in my .htaccess:
RewriteEngine On
RewriteRule ^(.*)$ /index.php?artid=$1


I have been told to set $newUrl = $_GET['newUrl']; ?

how does this work when I do not have a newUrl set in the address bar?

Currently, if I type mysite.com/bunchofstuff-here it will load my home page, which tells me that I have done something right so far.
 
Last edited:

chrishirst

Well-Known Member
Staff member
What a URL rewrite actually does is make a second internal HTTP request for the REAL URL that delivers the content, it doesn't do anything magically with the URLs, it simply masks or aliases where content actually is being served from.

Code:
RewriteRule ^(.*)$ /index.php?artid=$1


In English says;
for ANY number of characters between the start (^) of, to the end ($) of. the URL string that is requested at this server, request and serve the content from site.tld/index.php?artid=[the any number of characters matched by the regular expression]

so
Code:
site.tld/this-is-the-dogs-bollocks-you-know
would be re-sent to the server as

Code:
/index.php?artid=this-is-the-dogs-bollocks-you-know

So just as long as your server side code can find the right content indentified by "this-is-the-dogs-bollocks-you-know" it will be delivered to the user agent.
 

Glenn

Member
Just to experiment around, I put in my .htaccess file:
RewriteRule ^(.*)$ /index.php?newUrl=$1

Then I put in my index.php file:
$newUrl = $_GET['newUrl'];
echo "newUrl", $newUrl;

All I get out of this is "newUrl"
 

Glenn

Member
It's working now. I have to rewrite a few things now and see if everything works right. I'm 3 hours into parent teacher conference and I have had one parent so I have a little time here.
 
Top