Forum Moderators: phranque

Message Too Old, No Replies

neglect space and hypen in mod url rewrite urgent help needed

urgent help needed

         

varunkrish

3:37 pm on May 25, 2005 (gmt 0)

10+ Year Member



i use this mod_rewrtie
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)-(.*).php$ /phonemodel.php?mak=$1&mod=$2 [nc]

it points to phonemodel.php?mak=$mak&mod=$mod

suppose if i have a hyphen in the model field during request

ex:site.com/myx-5.php

the url rewrite not working

similarly

if if i have a hyphen space in the model field during request

ex.site.com/MY X-3.php

the url rewrite not working

is there a way to handle these cases or should i go for modifying database info?

jdMorgan

3:58 pm on May 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'll have to make some rules for creating URLs. If you want to use hyphens as a delimiter for mod_rewrite to identify variables, then you cannot use hyphens in your product names or model numbers. Use php's preg_replace to change them to some other character, such as "~".

Spaces are not valid characters for use in URLs. They must be encoded as %20.

Jim

varunkrish

6:23 pm on May 25, 2005 (gmt 0)

10+ Year Member



what if i can use under score "_" instead of "-"
RewriteRule ^(.*)_(.*).php$ /phonemodel.php?mak=$1&mod=$2 [nc]

how can i make url like

site.com/brand_my-c-5.php

jdMorgan

6:29 pm on May 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you are interested in the slight ranking advantage of using keywords in your URL, then use "-", ".", or "~".

Underscore joins the two words together into one single word, and will only help your ranking when people actually search for "Nokia_123" (including the underscore) and not for searches on "Nokia 123". The other characters above will match better.

Jim

varunkrish

6:37 pm on May 25, 2005 (gmt 0)

10+ Year Member



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

i did it this way one for models with hyphen and another for normal models

is it ok to do this?

varunkrish

7:03 pm on May 25, 2005 (gmt 0)

10+ Year Member



thanks a lot i am sticking to nokia-123.php

good work jim

thanks

jd01

7:06 pm on May 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi varunkrish,

Just a quick thought and then I'll let you two go back to what you were doing.

I think you might be better off to do something like this:

RewriteRule ^([^-]+)[-]([^-]+)\.php$ /phonemodel.php?mak=$1&mod=$2 [NC,L]
RewriteRule ^([^-]+)[-](.*)\.php$ /phonemodel.php?mak=$1&mod=$2 [NC,L]

The first rule will only qualify for requests with a single - then you can send them where you would like.

The second rule will catch any requests with multiple -'s and you can send them where you would like...

So, you could 'catch' models with a single hyphen and send them to a specific URL, and then you could catch 'makes' and 'models' and send them to another specific URL. (Of course the number of hyphens has to be correct for this to work EG 1 or more than 1, but if they are you could have the best of both worlds... hyphens and redirects.)

Hope this helps or gives another idea.

Justin

varunkrish

9:00 am on May 26, 2005 (gmt 0)

10+ Year Member



i am not clear with how you rewrite will work...

i have these kind of urls....

site.com/brand-model.php
(simple one)

site.com/brand-a-b.php
(little complex)

site.com/brand-a-b-c.php
(complex)

here a-b ad a-b-c are model names

will ur rewrite catch these urls?
please explain

varunkrish

9:03 am on May 26, 2005 (gmt 0)

10+ Year Member



RewriteRule ^([^-]+)[-]([^-]+)\.php$ /phonemodel.php?mak=$1&mod=$2 [NC,L]
RewriteRule ^([^-]+)[-](.*)\.php$ /phonemodel.php?mak=$1&mod=$2 [NC,L]

works like charm

thanks a lot