Forum Moderators: phranque

Message Too Old, No Replies

Mod Rewrite Rule not working

         

Farhaad Saleh

11:34 am on Mar 12, 2012 (gmt 0)

10+ Year Member



Hi Guys,

Hope your all well, this is my first post so please bear with me and i thank you for your patience in advance.

I am trying to write a pattern based mod rewrite rule for a full site migration.

I am trying to rewrite the following URL

http://www.example.com/Search/ProductNumber/14562/WorldWide/Momo+Val+Tech.htm

to

http://www.example.com/chem/momo-val-tech/

after reading various guides and forums i have come up with the following rule.

RewriteRule ^/Search/*[0-9,a-Z]momo+val+tech*[0-9,a-Z] www.example.com/chem/momo-val-tech/ [NC,R=301,L]


However due to my limited knowladge the redirect rule does not work, so i am reaching out and asking for help :)

Thanks for all help in advance.

lucy24

4:33 pm on Mar 12, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Individual points:
[0-9,a-Z]

This syntax is probably wrong but won't actually do any harm. It just means you're searching for alphanumerics and commas.

/*

means "zero or more slashes here". Just how many malformed URLs do you see regularly?
o+

means "one or more o's here". If your URLs contain literal plusses-- is that even legal? they may well come through as %2B. If they come through as + they will have to be escaped.

http://www.example.com/Search/ProductNumber/14562/WorldWide/Momo+Val+Tech.htm
...
^/Search/*[0-9,a-Z]momo+val+tech*[0-9,a-Z]

Your pattern doesn't fit the request you're matching. Start by reading up on Regular Expressions; there are errors all over the place. The Apache docs have a link to one RegEx information page, but you will probably be better off doing a general search and looking for a page that's written in a way you personally feel comfortable reading. This is important because you will be spending a lot of time studying RegEx instructions at first.

www.example.com...

In the target, include both the protocol and domain name: http://www.example.com et cetera.

But hey, you used "example.com". Cheers. First-time posters hardly ever get that right :)

g1smd

10:33 pm on Mar 12, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



In the question you ask to "rewrite a URL" but the example code shows a "redirect for a request".

In plain English what are you trying to do? User requests URL "X", server does ... what exactly? ...