SEO URL - reduce length of URL

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
werendle
Forum Newbie
Posts: 14
Joined: Tue Dec 07, 2010 5:10 am

SEO URL - reduce length of URL

Post by werendle »

[text]I have created search engine friendly URL's from my dynamic ones so "/index.php?page=home" now displays as "/index/page/home", is there are way of getting it to work with "/home" instead[/text]

Code: Select all

<ul class="menu">
	<a href="/dev/index/page/home">Home</a> &nbsp;&nbsp;&nbsp;&nbsp;<img src="images/present.png" height="38" width="35" alt="Logo"/>&nbsp;&nbsp;&nbsp;&nbsp;
	<a href="/dev/index/page/hints">Hints & Tips</a> &nbsp;&nbsp;&nbsp;&nbsp;<img src="images/present.png"height="38" width="35" alt=" logo"/>&nbsp;&nbsp;&nbsp;&nbsp;
	<a href="/dev/index/page/occasions">Occasions</a> &nbsp;&nbsp;&nbsp;&nbsp;<img src="images/present.png" height="38" width="35"alt=" logo"/>&nbsp;&nbsp;&nbsp;&nbsp;
	<a href="/dev/index/page/blog">Blog</a>&nbsp;&nbsp;&nbsp;&nbsp;<img src="images/present.png" height="38" width="35"alt=" logo"/>&nbsp;&nbsp;&nbsp;&nbsp;
	<a href="/dev/index/page/about">About</a> 

	
</ul>
<br>
<?php
	$page = $_GET['page'];
 		switch($page) 
			{
				case('home'):
					include ("home.php");
				break;
				case('about'):
					include ("about.php");
				break;
				case('occasions'):
					include ("occasions.php");
				break;
				case('blog'):
					include ("blog.php");
				break;
				case('hints'):
					include ("hints.php");
				break;
				default:
					include ("home.php");
			}
?>
[text]I have looked into the HTML Base tag, but not sure where to start, any help would be appreciated thanks[/text]
Last edited by werendle on Sun Dec 19, 2010 11:00 am, edited 1 time in total.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: SEO URL - reduce length of URL

Post by Jonah Bron »

We don't know, we can't see your .htaccess (assuming you used mod_rewrite).

P.S. you don't have to put your message in [text][/text ] tags.
werendle
Forum Newbie
Posts: 14
Joined: Tue Dec 07, 2010 5:10 am

Re: SEO URL - reduce length of URL

Post by werendle »

Hi, .htaccess now attached, sorry I missed it out

Code: Select all

RewriteEngine On

RewriteRule index/(.*)/(.*) index.php?$1=$2
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: SEO URL - reduce length of URL

Post by Jonah Bron »

This should work:

Code: Select all

RewriteEngine On

RewriteRule index/(.*) index.php?page=$1
werendle
Forum Newbie
Posts: 14
Joined: Tue Dec 07, 2010 5:10 am

Re: SEO URL - reduce length of URL

Post by werendle »

Hi Jonah, thanks for the reply, maybe I am missing something or have asked the wrong question.
with the current rewrite I have changed the displaying url from http://www.mydomain.com/index.php?page=home to http://www.mydomain.com/index/page/home which is much more friendly to the user, but what I am looking to achieve is http://www.mydomain.com/home. is it possible to use the mod rewrite to remove the /index/page/ from the url altogeather?
Thanks again for your help, Regards Will
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: SEO URL - reduce length of URL

Post by Jonah Bron »

Ah, then this should work.

Code: Select all

RewriteEngine On

RewriteRule (.*) index.php?page=$1
werendle
Forum Newbie
Posts: 14
Joined: Tue Dec 07, 2010 5:10 am

Re: SEO URL - reduce length of URL

Post by werendle »

Hi again, I have tried the change suggested, each link then returns the default case from indexp.php, I then tried changing the href link removing the /page/index and still no joy. Any other sugestions? many thanks again :?
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: SEO URL - reduce length of URL

Post by Jonah Bron »

Put an echo statement in index.php so we can find out what it's getting.
werendle
Forum Newbie
Posts: 14
Joined: Tue Dec 07, 2010 5:10 am

Re: SEO URL - reduce length of URL

Post by werendle »

Hi Jonah, what do you need to be echoed?
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: SEO URL - reduce length of URL

Post by Jonah Bron »

$_GET['page']
werendle
Forum Newbie
Posts: 14
Joined: Tue Dec 07, 2010 5:10 am

Re: SEO URL - reduce length of URL

Post by werendle »

Ok, url http://mydomain.com/dev/getstarted
echo output index.php

In index.php the default case statement is set to ('home')

Can I PM you the proper URL to take a look?
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: SEO URL - reduce length of URL

Post by Jonah Bron »

Sure, you can. But I just need to know what $_GET['page'] exactly contains...
werendle
Forum Newbie
Posts: 14
Joined: Tue Dec 07, 2010 5:10 am

Re: SEO URL - reduce length of URL

Post by werendle »

Jonah Bron wrote:Sure, you can. But I just need to know what $_GET['page'] exactly contains...
The Echo request displays 'index.php'

I have mailed you the url if that helps,

Thanks again
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: SEO URL - reduce length of URL

Post by Jonah Bron »

Hm, well, I haven't had too much experience with mod_rewrite. Perhaps someone more knowledgeable in that area can help you... sorry :(

Cheers.
werendle
Forum Newbie
Posts: 14
Joined: Tue Dec 07, 2010 5:10 am

Re: SEO URL - reduce length of URL

Post by werendle »

Hi Jonah, no problem, thank you so much for taking the time to have a look, best regards

Will
Post Reply