Search Engine Optimization
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignSearch Engine Optimization

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 23rd, 2004, 09:17 PM
codyg1985 codyg1985 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 16 codyg1985 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Creating static-like URLs with dynamic pages

I run a forum with approximately 43,000 posts and 1,700 members.

I would like to implement a system where the URLs for everything would display similar to what this forum uses.

However, I do not want to cache the content; this is purely for search engine ranking purposes, hence the location of the thread in this forum.

I followed a tutorial at one site about this which suggested creating two files: .htaccess and site, but that did not work for me.

Reply With Quote
  #2  
Old June 23rd, 2004, 09:58 PM
Instyle IT's Avatar
Instyle IT Instyle IT is offline
Instyle IT :: Design & Hosting
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Australia
Posts: 13 Instyle IT User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 46 m 49 sec
Reputation Power: 0
That is a lot of posts!!! Unfortunately the method I am about to suggest requires that you manual change the way your urls appear, but in a way so that the web server can still interpret them.

If you are running an apache webserver you could try using Apache's mod rewrite to make your URL's to appear static. The api can be found at http://httpd.apache.org/docs/mod/mod_rewrite.html

A user guide on how to use the mod rewrite function can be found here:
http://www.engelschall.com/pw/apache/rewriteguide/
I have used this apache feature on one of my php based sites (RatedBlue)
and it has yielded great results with google.

An example of the mod rewrite is:
old url: yourdomain.com/post.php?id=884
You need to rewrite the old url to look similar to this:
new url: yourdomain.com/post/884/

Through the use of the .htaccess apache mod rewrite method apache will interpret each part of the url as a get variable. e.g. variable 1 = post, variable 2=884

Good luck and post again if you need some pointers implementing it!!!

Reply With Quote
  #3  
Old June 24th, 2004, 04:55 PM
codyg1985 codyg1985 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 16 codyg1985 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unfortunately, I do not have access to the apache source files on the server to edit to make this work.

Reply With Quote
  #4  
Old June 24th, 2004, 08:03 PM
codyg1985 codyg1985 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 16 codyg1985 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I see, those mods can be done with .htaccess files.

Well, I implemented a system which uses both .htaccess and a php script.

Unfortunately, the system does not automatically change the URLs for me; I have to manually change them in the skin templates.

I would also like to know how to handle certain situations.

Here is the .htaccess code:

Code:
php_value auto_prepend_file prepend.php
php_value auto_append_file append.php

RewriteEngine On
RewriteRule ^([^/]+)_([0-9]+)\.html$ index.php?$1=$2 [L]


prepend.php:

PHP Code:
<?php 
/* 
* This function will transform dynamic html links into static ones. 
*/ 
function doURI$buffer ) { 
    
$serverNoWww preg_quotepreg_replace"/(www\.)?(.+)/i""$2"
                                             
$_SERVER'SERVER_NAME' ] ) ); 
    
$serverName "(http:\/\/(www\.)?".$serverNoWww.")?"

    
/* 
     * Convert:     
     *     <a href="index.php?option=andrea&Itemid=1859" 
     *     <a href="/mambo/index.php?option=andrea&Itemid=1859" 
     *     <a href="http://example.com/mambo/index.php?option=andrea&Itemid=1859" 
     *     <a href="http://www.example.com/mambo/index.php?option=andrea&Itemid=1859" 
     * to: 
     *     <a href="andrea_1859.html" 
     *     <a href="/mambo/andrea_1859.html" 
     *     <a href="http://example.com/mambo/andrea_1859.html" 
     *     <a href="http://www.example.com/mambo/andrea_1859.html" 
     */

    
$buffer preg_replace"/<a href=\"".$serverName
                            
"(\/forum\/)?index\.php\?([^\/]+)=([0-9]+)\"/i"
                            
"<a href=\"$1$3$4_$5.html\""
                            
$buffer ); 

    return 
$buffer


ob_start"doURI" ); 

?>


I should mention that I got this at SitePoint.

I would like to know how I would allow myself to change URL's such as these:

http://www.site.com/forum/index.php...iew=getlastpost
http://www.site.com/forum/index.php...=3&hl=goat+boat

Reply With Quote
  #5  
Old June 24th, 2004, 11:19 PM
Instyle IT's Avatar
Instyle IT Instyle IT is offline
Instyle IT :: Design & Hosting
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Australia
Posts: 13 Instyle IT User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 46 m 49 sec
Reputation Power: 0
I do believe you can do all your uri "interpreting" in apache rather than mix a php function with it. It will be quicker server side if you do it in your .htaccess.

This is what I would have as my .htaccess file in the /forum/ folder (if you want to make this your root .htaccess then the RewriteBase should be something like this /forum/)if I wanted to convert the below url:
http://www.site.com/forum/index.php...iew=getlastpost CONVERT TO
http://www.site.com/forum/3_getlastpost.html
the second rewrite rule is to convert this url:
http://www.site.com/forum/index.php...=3&hl=goat+boat CONVERT TO
http://www.site.com/forum/3_hl.html

----------------------------------------------.htaccess in /forum/ directory--------------------------------------------
RewriteEngine On
RewriteBase /
RewriteRule ^([^/]+)_([a-z0-9]+)\.html$ index.php?showtopic=$1&getlastpost=$2 [QSA]
RewriteRule ^([^/]+)_([a-z0-9]+)\.html$ index.php?showtopic=$1&hl=$2 [QSA]

---------------------------------------------- //.htaccess ------------------------------------------------------------------------
As you can see you need to create a rewrite rule for each "GET" variable that is passed. Besides changing the urls to the correct format in your skins template you do not have to add anything extra to your scripts. This is because apache passes the variables, etc to php when it interprets the url!

By the way, the [QSA] stands for append query string,

What is your site URL so I can have a look???

Reply With Quote
  #6  
Old June 26th, 2004, 12:55 PM
codyg1985 codyg1985 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 16 codyg1985 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I think I figured out how to get the script to parse out url's with those extra "get" options.

My forums URL is at http://www.nextl3vel.net/forum.

Reply With Quote
  #7  
Old June 27th, 2004, 06:16 AM
Instyle IT's Avatar
Instyle IT Instyle IT is offline
Instyle IT :: Design & Hosting
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Australia
Posts: 13 Instyle IT User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 46 m 49 sec
Reputation Power: 0
Just had a look at your forum. The way you have rewritten the urls looks good. Congratulations, looks static. Now it is time for you to move on and put the same method into action with all the other urls on your site, e.g. news.

By the way, did you end up using the php script? Or did you manage to do it with mod_rewrite?

Reply With Quote
  #8  
Old June 27th, 2004, 08:41 AM
codyg1985 codyg1985 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 16 codyg1985 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I got it to work using mod_rewrite by using the method you suggested.

I have also used this technique on the news sections of my website now.

Reply With Quote
  #9  
Old July 2nd, 2004, 07:22 PM
Instyle IT's Avatar
Instyle IT Instyle IT is offline
Instyle IT :: Design & Hosting
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Australia
Posts: 13 Instyle IT User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 46 m 49 sec
Reputation Power: 0
I just checked out your news section and all is looking great. Glad that you could implement it without too much trouble. Looks like you have a good high traffic site there and google has begun to index your new static pages

Good luck.

Eden
Instyle IT - Australian Web Design and Web Hosting

Reply With Quote
  #10  
Old July 4th, 2004, 05:10 PM
codyg1985 codyg1985 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 16 codyg1985 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by Instyle IT
I just checked out your news section and all is looking great. Glad that you could implement it without too much trouble. Looks like you have a good high traffic site there and google has begun to index your new static pages

Good luck.

Eden
Instyle IT - Australian Web Design and Web Hosting


Yes, I have also noticed search engines already indexing these web pages.

This will definately come in a lot of handy.

Reply With Quote
  #11  
Old July 7th, 2004, 02:36 AM
kyliecoast kyliecoast is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 92 kyliecoast User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 55 m 12 sec
Reputation Power: 0
I need to do the same thing with my website

http://www.ozemall.com.au

I'm not sure how the above instructions apply to my site.

My index.php finds my shopping categories by their catid variable

This didn't work:

----------------------------------------------.htaccess in /forum/ directory--------------------------------------------
RewriteEngine On
RewriteBase /
RewriteRule ^([^/]+)_([a-z0-9]+)\.html$ index.php?catid=$1&hl=$2 [QSA]

---------------------------------------------- //.htaccess --------------------------------------------------------------------

Reply With Quote
  #12  
Old October 11th, 2004, 04:10 PM
Flaky_Jake Flaky_Jake is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 2 Flaky_Jake User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
mod_rewrite and page generation

Interested in what your saying...

I have a url that looks like this

..orderitem.php?cid=803&tid=1&group=pop&item_title=fantasia+
barrino+believe&id=17618

how would i go about setting a system up to rewrite this on apache, and would i have to recreate all the static files manually, or is there a system one could use to generate folders and files [static] on a remote server...

many thanks

Reply With Quote
  #13  
Old October 20th, 2004, 04:34 AM
Instyle IT's Avatar
Instyle IT Instyle IT is offline
Instyle IT :: Design & Hosting
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Australia
Posts: 13 Instyle IT User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 46 m 49 sec
Reputation Power: 0
Quote:
Originally Posted by Flaky_Jake
Interested in what your saying...

I have a url that looks like this

..orderitem.php?cid=803&tid=1&group=pop&item_title=fantasia+
barrino+believe&id=17618

how would i go about setting a system up to rewrite this on apache, and would i have to recreate all the static files manually, or is there a system one could use to generate folders and files [static] on a remote server...

many thanks


Flaky_Jake your problem can simply be solved using apache mod_rewrite.

Here is what you would need your .htaccess file to look like, please note that all five variable must be present for the rewrite below to work. If less variables are present then you will need to use more than one rule.

---------------------------------------.htaccess in root directory-----------
RewriteEngine On
RewriteBase /
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)\.php$ orderitem.php?cid=$1&tid=$2&group=$3&item_title=$4$id=$5 [QSA]
--------------------------------------//.htaccess---------------------------
Thats great but what does that mean for you? Well you need to alter your php files that contain urls in this format:

www.mydomain.com/orderitem.php?cid=803&tid=1&group=pop&item_title=fantasia+barrino+believe&id=17618

and make the urls look like this

www.mydomain.com/803/1/pop/fantasia+barrino+believe/17618.php

I hope this is some benefit to you!

Reply With Quote
  #14  
Old November 15th, 2004, 03:41 PM
Flaky_Jake Flaky_Jake is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 2 Flaky_Jake User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
"Thats great but what does that mean for you? Well you need to alter your php files that contain urls in this format:

www.mydomain.com/orderitem.php?cid=803&tid=1&group=pop&item_title=fantasia+barrino+believe&id=17618

and make the urls look like this

www.mydomain.com/803/1/pop/fantasia+barrino+believe/17618.php"

thats great and I understand the htaccess rule, but how do i do the latter. It pulls data from the database so has to be dynamic, or are you saying that the url has to look like that, when a user clicks on it, so I just rewrite without the parameters and instead submit "/" between the dynamic fields???????

Reply With Quote
  #15  
Old December 8th, 2004, 06:55 PM
Instyle IT's Avatar
Instyle IT Instyle IT is offline
Instyle IT :: Design & Hosting
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Australia
Posts: 13 Instyle IT User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 46 m 49 sec
Reputation Power: 0
Quote:
Originally Posted by Flaky_Jake
thats great and I understand the htaccess rule, but how do i do the latter. It pulls data from the database so has to be dynamic, or are you saying that the url has to look like that, when a user clicks on it, so I just rewrite without the parameters and instead submit "/" between the dynamic fields???????


Yes that is correct Flaky Jake, get rid of the parameter names and the = signs and substitute a "/" in there place, here is an example:

Old way to submit data:
www.example.com?id=23&price=10.50&name=Johnny

New way with parameters and = removed:
www.example.com/23/10.50/Johnny.php
Note: you can append .php or .html or even a trailing forward slash to the end of the URL as long as it matches up with your .htaccess rules.

Normally when you submit your form or url using the GET variables you would say
www.example.com?id=<?=$id;?>&price=<?=$price;?>&name=<?=$name;?>
But now you want to use mod rewrite so you write edit your php files to say
www.example.com/<?=$id;?>/<?=$price;?>/<?=$name;?>.php

This will give you the desired outcome you are looking for.

Sorry for being ambiguous in the previous post, I hope this clears things up for you if you haven't implemented it yet.

Reply With Quote