Shortcode...URL. /contact-us/

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
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Shortcode...URL. /contact-us/

Post by simonmlewis »

Hi

This seems a common thing to do, but I don't know how.......

How do you setup script so a page can be viewed through a short url.
For example, http://www.mywebpage.co.uk/conveyancing-quote/

Can a script be made so that /conveyancing-quote/ is the shorturl for
http://www.mywebpage.co.uk/index.php?page=45&s=332 ??

I know how to do a redirector in HTML, but this is different.

Simon
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Shortcode...URL. /contact-us/

Post by requinix »

There's a rule on the server that says "if this thing can't be found, go here". It happens internally so you (the user) don't see that you're being redirected to index.php?...

If you're using Apache with mod_rewrite:

Code: Select all

RewriteEngine On
RewriteRule %{REQUEST_FILENAME} !-f
RewriteRule %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?shortcut=$0
Your index.php has two purposes now: one is to serve the front page to the website, the other is to handle shortcuts. (You could have a PHP file specifically handle shortcuts if you wanted.)

index.php can look at $_GET["shortcut"] to see if it's supposed to serve something. It gets the "conveyancing-quote" and decides what to do from there.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Shortcode...URL. /contact-us/

Post by simonmlewis »

Thank you.

I will look up and research $_GET["shortcut"] to see how to make it all happen, as it looks like a standard PHP method.

Regards
Simon
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Shortcode...URL. /contact-us/

Post by simonmlewis »

Hi - this doesn't seem as straight forward as I thought, and there isn't all that much about it on the web.

ie. I would have thought there's be a /page/ type script somewhere, with the url it directs to, and an include or something in the index.php file that does it all.

Not as simple as that??
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply