Forum Moderators: phranque

Message Too Old, No Replies

Mod Rewrite help needed

         

netplay

5:52 pm on Aug 14, 2010 (gmt 0)

10+ Year Member



Hi Guys,

I'm a newbie to Apache rewrite, and am struggling to do the following rewrite

From
http://www.example.com/?module=home&action=index

to

http://www.example.com/home/index

The module & action parameters will always be there in the same order.

Any addtional parameters, should just be parameter/value pairs

eg.
http://www.example.com/?module=home&action=index&category=news&article=1

to

http://www.example.com/home/index/category/news/article/1

I'd be very grateful for a any help and pointers.

Thanks,
Alan

jdMorgan

1:13 pm on Aug 15, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you switching your site from using scripts to using static pages? If so, then your approach here is correct.

If, on the other hand, you are trying to use static "SEO friendly" URLs to invoke scripts on your server, then this approach is entirely backwards, and instead what you're looking to do is:
  1. Change all links published on your site to the new "friendly" format -- by editing the script(s) and/or database(s).
  2. Internally rewrite requests for these new friendly URLs, when requested from your server, to the correct dynamic filepath inside the server, including the information passed in the friendly URLs as query parameters for the script to use.
  3. Externally redirect direct client requests for the old "unfriendly" URLs to the new friendly ones. Note the word "direct," as ingnoring this details leads to an infinite loop due to interaction with the code for step 2.

Keep in mind the following:
  1. URLs are defined by links on Web pages. They exist as soon as they are published, whether or not they resolve to an existing domain or object within a domain. URLs are used "out on the Web."
  2. A server's main task is to associate a URL in an incoming request with the proper file or script needed to fulfill that request. In this regard, it converts a URL to a filepath. The filepath is used only "here, inside the server," and should never appear "out there on the Web."
  3. mod_rewrite can be used to modify the default URL-to-filepath translation.

For more information, see the following thread in our Apache Forum Library [webmasterworld.com]: Changing Dynamic URLs to Static URLs -- Implementing search engine friendly URLs with mod_rewrite [webmasterworld.com]

Our Forum Charter [webmasterworld.com] also contains links to very useful resources. Be sure that you are familiar with this material before proceeding to modify your site, as the results could otherwise be disastrous.

Jim

netplay

3:39 pm on Aug 18, 2010 (gmt 0)

10+ Year Member



Thanks Jim,

I was looking at internal server rewrite

So, any incoming request for

http://www.example.com/home/index/category/news/article/1

would be resolved

http://www.example.com/?module=home&action=index&category=news&article=1 so that the script can read the GET variable.

I need help on the regular expression, what would it be ?I can just about manage the basic rewrite

Thanks Jim for taking the time

Alan

g1smd

6:50 pm on Aug 18, 2010 (gmt 0)

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



Let's see your code.

This type of rewrite is discussed at least several times each month. There are hundreds of prior threads with example code, especially those highlighted above.