Author Topic: Url rewriting  (Read 1107 times)

0 Members and 1 Guest are viewing this topic.

Offline hilflo

  • Full phpd Member
  • ***
  • Posts: 98
  • Karma: 2
  • Sorry for my bad english
    • View Profile
    • Les félés
Url rewriting
« on: December 16, 2009, 01:33:46 AM »
A way to have beautiful url and more SEO.
Instead of having a url like that : http://www.phpdirector.co.uk/demo/videos.php?id=2
You have : http://www.phpdirector.co.uk/demo/video-Skateboarding+Dog-2

Create a .htaccess file
Code: [Select]
Options +FollowSymlinks
RewriteEngine on
Rewritebase /

RewriteRule ^video-(.*)-([0-9]+)$   /videos.php?name=$1&id=$2 [L]
RewriteRule ^category-(.*)-([0-9]+)$   /index.php?name=$1&cat=$2 [L]


Now you need to modify all your url to match wich this .htacces.
For example in index.php

<a href="videos.php?id={$videos[mysec].id}" class="bluebtn">{$LAN_14}[/url]
Become
<a href="video-{$videos[mysec].name|urlencode}-{$videos[mysec].id}" class="bluebtn">{$LAN_14}[/url]

In category.tpl
<a href="index.php?cat={$cat[cat].id}">
become
<a href="category-{$cat[cat].name}-{$cat[cat].id}">

You can see an example on http://www.jeu-en-ligne.bzh.be
Clic on a game to see the result.
« Last Edit: December 18, 2009, 11:19:30 PM by hilflo »

Offline Jeff

  • Global Moderator
  • Sr phpd Member
  • *****
  • Posts: 359
  • Karma: 5
  • Need help? Feel free to ask.
    • View Profile
Re: Url rewriting
« Reply #1 on: December 16, 2009, 01:07:43 PM »
great job man!!!! that was on my todo list :-P Woooo its now 1 thing shorter

Offline xsnoboard

  • phpd Basic Member
  • **
  • Posts: 39
  • Karma: 0
    • View Profile
    • My Vid Space
Re: Url rewriting
« Reply #2 on: December 18, 2009, 04:02:39 PM »
I have a suggestion to better optimize the URL rewrite.


Anyway you can change it so it displays like this

site.com/video-This-Video-Is-Funny-131

The dashes hold the URL together. For example look at your copy and paste of the link, it cut off the end. Also looks better with dashes.

Offline hilflo

  • Full phpd Member
  • ***
  • Posts: 98
  • Karma: 2
  • Sorry for my bad english
    • View Profile
    • Les félés
Re: Url rewriting
« Reply #3 on: December 18, 2009, 11:21:02 PM »
You are right. I have edited the code. Now we have "+" instead of space

Offline xsnoboard

  • phpd Basic Member
  • **
  • Posts: 39
  • Karma: 0
    • View Profile
    • My Vid Space
Re: Url rewriting
« Reply #4 on: December 19, 2009, 02:11:19 AM »
Also, I noticed that many of my links stopped working. Realized so far that only a title with a " in it, will not create the link properly. Is there anyway to make it so can process it correctly? or anyway to make it so it doesn't display any special characters in the link and just letters and numbers?

Offline Chris (krissy)

  • Project Leader
  • Sr phpd Member
  • *****
  • Posts: 219
  • Karma: 1000
    • View Profile
    • PHPDirector
Re: Url rewriting
« Reply #5 on: December 19, 2009, 01:44:36 PM »
Can someone from the developer team add this to the next version as an option?

Offline xsnoboard

  • phpd Basic Member
  • **
  • Posts: 39
  • Karma: 0
    • View Profile
    • My Vid Space
Re: Url rewriting
« Reply #6 on: December 19, 2009, 03:08:58 PM »
How could I change the "+" to be a "-".

How come I setup the rewrite mode to remove any special characters such as `!@#$%^&*()

Thanks! You have been a great help!

Offline hilflo

  • Full phpd Member
  • ***
  • Posts: 98
  • Karma: 2
  • Sorry for my bad english
    • View Profile
    • Les félés
Re: Url rewriting
« Reply #7 on: December 20, 2009, 09:19:57 PM »
I don't fin a way to replace + by - but that's right, it will be better.

Fo special chars, yu need to creat a function to replace all this character by others but I don't konw how to do that

Offline funak

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
    • View Profile
Re: Url rewriting
« Reply #8 on: January 12, 2010, 08:52:40 PM »
great feature - but not added to v 0.3 released on 1/1/2010  :(

Offline FireDart

  • Project Leader
  • Pro Member
  • *****
  • Posts: 406
  • Karma: 4
    • View Profile
    • FireDart
Re: Url rewriting
« Reply #9 on: January 13, 2010, 02:44:19 AM »
This mod was introduce right before release, we are now coding Version 1.0 and we will try to add this(No guaranty thought).

Time to make a "1.0 - Planned features / Actual Features" post.

Offline xsnoboard

  • phpd Basic Member
  • **
  • Posts: 39
  • Karma: 0
    • View Profile
    • My Vid Space
Re: Url rewriting
« Reply #10 on: January 13, 2010, 02:34:46 PM »
Quote
Now you need to modify all your url to match wich this .htacces.
For example in index.php

Just to let you guys know. In the instructions it says to edit index.php but you really edit index.tpl in your templates folder. Just incase some of you were confused.  8)