Rewrite in .htaccess

  • rady
  • Newbie
  • Newbie
  • rady
  • Posts: 8

Post 3+ Months Ago

Hi guys, i'm working on making my urls search engine friendly and i would like to ask if anyone knows how to work with the .htaccess file
many of my links look like:

A)
file.php?id=123
how can i change that so that it would look like file123.php

B)
file.php?date=yyyy-mm-dd
how can i change it so that it would look like file-yyyy-mm-dd.php

C)
file.php?first=FirstName&last=LastName
hiw can i change it so that it would look like file_FirstName_LastName.php

did any of you worked with such things?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • veedee
  • Graduate
  • Graduate
  • User avatar
  • Posts: 110

Post 3+ Months Ago

Code in C), I haven't try it yet, but I think will work:
A)
file.php?id=123
how can i change that so that it would look like file123.php
Code: [ Select ]
RewriteEngine On
RewriteRule ^file(.*)\.php$ file.php?id=$1
  1. RewriteEngine On
  2. RewriteRule ^file(.*)\.php$ file.php?id=$1

B)
file.php?date=yyyy-mm-dd
how can i change it so that it would look like file-yyyy-mm-dd.php
Code: [ Select ]
RewriteEngine On
RewriteRule ^file-(.*)\.php$ file.php?date=$1
  1. RewriteEngine On
  2. RewriteRule ^file-(.*)\.php$ file.php?date=$1

C)
file.php?first=FirstName&last=LastName
hiw can i change it so that it would look like file_FirstName_LastName.php
Code: [ Select ]
RewriteEngine On
RewriteRule ^file_(.*)_(.*)\.php$ file.php?first=$1&last=$2[L]
  1. RewriteEngine On
  2. RewriteRule ^file_(.*)_(.*)\.php$ file.php?first=$1&last=$2[L]
  • BooGiE_MaN
  • Proficient
  • Proficient
  • User avatar
  • Posts: 387
  • Loc: Cape Town, South Africa

Post 3+ Months Ago

In addition to that, if you want a specific page to have a specific page name you can go

Code: [ Select ]
RewriteEngine On
RewriteRule ^BetterNameForPage.html file.php?id=123
  1. RewriteEngine On
  2. RewriteRule ^BetterNameForPage.html file.php?id=123

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 7 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.