Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite to change url

mod rewrite to change url

         

varunkrish

6:52 pm on May 24, 2005 (gmt 0)

10+ Year Member



have a phone site

i have a phone page like

its works like
www.site.com/phone.php?id=4

i used mod rewrite like thisfitst
PHP Code:
RewriteEngine On
RewriteBase /
RewriteRule ^([^/.]+)/?$ /phone.php?id=$1 [L]

so url is like this site.com/4 and it points to site.com/phone.php?id=4

PHP Code:
RewriteEngine On
RewriteBase /
RewriteRule ^phone.*-([0-9]*).html$ /phone.php?id=$1 [L]

site.com/phone-4.html and it points to site.com/phone.php?id=4

i want to build url like site.com/brand-model-id.php

but i want to use only id parameter

how to do?

i want to use the brand and model only in url

but only id is the parameter passed to phone.php

how do i do it
please help

jdMorgan

10:42 pm on May 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



varunkrish,

Welcome to WebmasterWorld!

Our forum charter [webmasterworld.com] contains a link to a regular-expressions tutorial which you may find helpful.

> i want to build url like site.com/brand-model-id.php


RewriteRule ^[^\-]+-[^\-]+-(.+)$ /phone.php?id=$1 [L]

First group matches any characters up to the first hyphen in requested URL -- this is the brand.
Hyphen matches first hyphen in requested URL.
Second group matches any characters up to the second hyphen -- this is the model.
Last group matches any remaining characters, and they are copied into variable $1.

Jim

varunkrish

12:50 am on May 25, 2005 (gmt 0)

10+ Year Member



works brilliantly thanks a lot

but where's the extension?

i want to use only ".php" how can i do that?

varunkrish

12:51 am on May 25, 2005 (gmt 0)

10+ Year Member



figured it out

RewriteEngine On
RewriteBase /
RewriteRule ^[^\-]+-[^\-]+-(.+).php$ /phone.php?id=$1

is it correct

varunkrish

1:16 am on May 25, 2005 (gmt 0)

10+ Year Member



i have another page say of the form

[domain.com...]

how do i make it of the form

[domain.com...]

i am new to mod_rewrite

please help

jdMorgan

1:59 am on May 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> Is this correct?

Use this, it'll be faster:


RewriteEngine On
RewriteBase /
RewriteRule ^[^\-]+-[^\-]+-([^.]+)\.php$ /phone.php?id=$1

I'll leave the rest to you, since you figured out the extension. :) We're here to help you learn (See forum Charter [webmasterworld.com]). If you don't want to do it yourself, there is always our Commercial Exchange [webmasterworld.com] forum.

Jim

varunkrish

2:27 am on May 25, 2005 (gmt 0)

10+ Year Member



thanks a lot for quick responses

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^[^\-]+-[^\-]+-(.+).php$ /phone.php?id=$1
RewriteRule ^(.*)-(.*).php$ /phonemodel.php?mak=$1&mod=$2 [nc]

i am using this for getting url
site.com/brand-model.php

is it correct? any optimization