1,105,371 Community Members

creating seo friendly urls

Member Avatar
zoreli
Newbie Poster
12 posts since May 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi everyone

What I am trying to do:

I am trying to rewrite my urls in seo frendly url. For that purpose I create the following table in my database:

CREATE TABLE `seourls` (
`path` varchar(255) NOT NULL,
`url` varchar(255) NOT NULL,
PRIMARY KEY (`path`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- 
-- Dumping data for table `seourls`
-- 

INSERT INTO `seourls` (`path`, `url`) VALUES ('building-and-construction', 'halls_en.php?fairid=64'),
('online-fair-platform', 'articles.php?artid=89'),
('add-your-company', 'articles_en.php?artid=89'),
('rough-construction', 'companies_en.php?fairid=64&ehallid=118');

Now... I create a php file, named url_rewrite.php Here is the code that I have there:

         function get_path() {   

         $url1 = $_SERVER["REQUEST_URI"];
         $url = str_replace('/tempfolder/', '', $url1); 
         $startpath=mysql_result(mysql_query("SELECT path FROM seourls WHERE url='$url'"),0,"path");

         //$add="http://www.mydomain.com/tempfolder/";
         //$path =  $add.''.$startpath;
         //header("Location: $path");

         header("Location: $startpath");
         }

What is my problem:

I don't know how to proceed further. I know that I have to use .htaccess to rewrite the url stored in $startpath variable, but I don't know to do that. I have very limited knowledge of regular expressions and 0 knowledge of apache.

Anyone can help with the .htaccess code and (if needed) changes of the url_rewrite.php file? My urls must be seo frendly, but I am not sure if the code header("Location: $startpath"); can be considered as seo friendly redirect.

Regards, Zoreli

Member Avatar
Squidge
Posting Pro in Training
476 posts since Dec 2009
Reputation Points: 101 [?]
Q&As Helped to Solve: 75 [?]
Skill Endorsements: 6 [?]
 
0
 

There are loads of MOD_REWRITE tutorials about:
http://www.addedbytes.com/for-beginners/url-rewriting-for-beginners/

It can be a pain, but read through some

Member Avatar
zoreli
Newbie Poster
12 posts since May 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi Squidge

Thanks for your response.

I make an extensive research on many .htaccess tutorials, but i didn't find any specific tutorial that explain or is close to the task that I want to achieve.

Can you please post some example of .htaccess code that will solve my problem?

Regards,Zoreli

Member Avatar
Squidge
Posting Pro in Training
476 posts since Dec 2009
Reputation Points: 101 [?]
Q&As Helped to Solve: 75 [?]
Skill Endorsements: 6 [?]
 
1
 

RewriteEngine on
RewriteBase /
RewriteRule ^page/([0-9]+)\.php$ index.php?key=$1

Here is start of one that i use, it rewrites any URL that has index.php?key=$ and re assigns to /page/[keyid]

I have not seen url rewrite done via a DB before, but hey i am sure it will go just as well.
(remove comments)
ReWriteEngine on //Start your rewrite module
RewriteBase / //Sets the base, so all files read/written from [site]/

RewriteRule ^online-fair-platform/([0-9]+)$ articles.php?artid=$1

This would rewrite the link
site.something/articles.php?artid=1554
into
site.something/online-fair-platform/1554

Hope that helps

Member Avatar
diafol
Where are my eyes?
12,977 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,848 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
1
 

I've found this site absolutely brilliant for mod rewrites: http://www.generateit.net/mod-rewrite/

That site gives:

RewriteEngine On
RewriteRule ^online-fair-platform/([^/]*)$ /articles.php?artid=$1 [L]
Member Avatar
Squidge
Posting Pro in Training
476 posts since Dec 2009
Reputation Points: 101 [?]
Q&As Helped to Solve: 75 [?]
Skill Endorsements: 6 [?]
 
0
 

I've found this site absolutely brilliant for mod rewrites: http://www.generateit.net/mod-rewrite/

Nice tool :)

Member Avatar
zoreli
Newbie Poster
12 posts since May 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi dlafol

I've found this site absolutely brilliant for mod rewrites: http://www.generateit.net/mod-rewrite/

Tool seems promsing, but I need database driven solution. Thanks anyway for the link, I may use it for simple sites.

Member Avatar
zoreli
Newbie Poster
12 posts since May 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi Squidge

I have not seen url rewrite done via a DB before, but hey i am sure it will go just as well.
(remove comments)
ReWriteEngine on //Start your rewrite module
RewriteBase / //Sets the base, so all files read/written from [site]/
RewriteRule ^online-fair-platform/([0-9]+)$ articles.php?artid=$1
This would rewrite the link
site.something/articles.php?artid=1554
into
site.something/online-fair-platform/1554

I think that only way this to be done with the database is all requests for the site to be REDIRECTED TO ulr_rewrite.php and from there I shold again redirect the users...but the question is how to do it? And is that seo frendly?

Any idea?

Regards,Zoreli

Member Avatar
Squidge
Posting Pro in Training
476 posts since Dec 2009
Reputation Points: 101 [?]
Q&As Helped to Solve: 75 [?]
Skill Endorsements: 6 [?]
 
0
 

zoreli if i may, why are you using the DB for this?

i think you maybe over complicating things

Member Avatar
zoreli
Newbie Poster
12 posts since May 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Well, there will be way too many pages on the site, so I can't simply add rules in the .htaccess. Sure enough this code will be reused in each and every project after...

Member Avatar
Squidge
Posting Pro in Training
476 posts since Dec 2009
Reputation Points: 101 [?]
Q&As Helped to Solve: 75 [?]
Skill Endorsements: 6 [?]
 
0
 

You could use the naming style you want as the key indetifier instead of a numerical one. So for example you URL would be somesitename.blah/ulr_rewrite.php?indentifier=online-fair-platform

You will still be required to use .htaccess to rewrite it to somesitename.blah/online-fair-platform
with a rewrite rule something like

RewriteRule ^\$/([^/]*)$ /ulr_rewrite.php?indentifier=$

Please note this is not tested, and may not function, or may even require tweaking :)

Hope that helps

Member Avatar
diafol
Where are my eyes?
12,977 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,848 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
0
 

Most big sites these days route their requests through the index.php page and just use includes/templates to serve the info requested from the url (mod-rewritten).

Surely all you need is a similar setup with:

a url like: index.php?article=345
being placed into html by php/mysql as /345/online-fair/

If you have the slugified title of the article in the DB already, why not use it to build your url for a link? All your mod-rewrite then has to do is ignore the title and concentrate on the number.

Member Avatar
muktesh
Newbie Poster
3 posts since Feb 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-1
 

SEO friendly url are the url that are easy to remember user and easy to search. see this to create SEO SEO friendly url http://techathon.mytechlabs.com/seo-friendly-url-with-php/

Member Avatar
Squidge
Posting Pro in Training
476 posts since Dec 2009
Reputation Points: 101 [?]
Q&As Helped to Solve: 75 [?]
Skill Endorsements: 6 [?]
 
0
 

8m month old thread really????

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: