Forum Moderators: phranque

Message Too Old, No Replies

Beginner: Mod Rewrite Help

         

unimaginative id

6:03 pm on Dec 6, 2003 (gmt 0)

10+ Year Member



please help...

the real page is:
/item.php?id=14

but I want to use this:

/widget_item_14.htm

I could easily do it without the widget, but I want that there for the search engines, so basically i need everything from "/" up until "_item" to be ignored. I hope that makes sense, thanks in advance.

jdMorgan

6:57 pm on Dec 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



unimaginative id,

Welcome to WebmasterWorld [webmasterworld.com]!

For a backgrounder and links to good tutorials, check out this Introduction to mod_rewrite [webmasterworld.com].

You don't actually want to ignore "/widget_item_" - you will need to match it (detect it) in order to extract the parameter (14 in your example) that you need to pass to your script. Similarly, you'll want to match the trailing ".htm" to make sure you're rewriting only the desired requests.

You will need to modify your script or page templates to output friendly URLs for users and search engine spiders. mod_rewrite [httpd.apache.org] will then convert them to the proper format to call you script.

Have a look at the Introduction cited above *and* at the links cited in that post -- You'll need to understand this material in order to get your code working. We are glad to help you get your code working, but please review our charter [webmasterworld.com].

Jim

unimaginative id

8:36 pm on Dec 8, 2003 (gmt 0)

10+ Year Member



sorry for not replying to my own post, I forgot I'd even joined WebmasterWorld, anyway I worked it out, but thanks for the help anyway. If anyone is interested this is what I used:

RewriteRule ^(.*)\_item(.*)\.htm$ /item\.php?id=$2

so pretty obvious really