Forum Moderators: phranque

Message Too Old, No Replies

Simple rewrite

         

dkin

9:03 am on Sep 3, 2005 (gmt 0)

10+ Year Member



I have all my urls rewritten like this

RewriteRule games/xbox_games/(.*)\.html$ /games.php?op=detail&name=$1

I would like to add a new variable so the url would look like this

/games.php?op=detail&name=$1&console=$2

what would my static rewrite rule look like?

jdMorgan

3:13 pm on Sep 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That depends entirely on what your new two-variable static URLs look like.

We don't write code on demand here, but our forum charter and the Apache Server section of the WebmasterWorld library contain several useful references and tutorials to get you started.

Jim

dkin

6:42 pm on Sep 3, 2005 (gmt 0)

10+ Year Member



Im not asking for code on demand, Im simply asking to be pointed in the right direction, I am obviously new to the apache forum because I have no idea what your talking about.

Please be a little more specific.

This is what the variables would look like.

/games.php?op=detail&name=widgets&console=widgetplayer

jdMorgan

7:03 pm on Sep 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You have to let us know
...what your new two-variable static URLs look like.
before we can answer your question.

If /games/xbox_games/(.*)\.html is to be rewrriten to /games.php?op=detail&name=$1

then *what* is to be rewritten to /games.php?op=detail&name=$1&console=$2 ?

The static URL must contain all the information needed to construct the dynamic script call, and the RewriteRule must take the static URL's structure into account.

Jim

dkin

8:04 pm on Sep 3, 2005 (gmt 0)

10+ Year Member



the new url would look like this

games/xbox_games/$var1/console/$var2.html

thats all.

Thank you

jd01

5:53 am on Sep 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just put the regex in the URLs where you need them:

RewriteRule games/xbox_games/([^/]+)/console/([^.]+)\.html /games.php?op=detail&name=$1&console=$2 [L]
RewriteRule games/xbox_games/([^.]+)\.html$ /games.php?op=detail&name=$1 [L]

* Changed to a slightly more efficient forward-looking negative pattern.

** The order of the rules *will* matter if you use (.*), because both the URL patterns will match. Using a negative pattern rather than a catch all allows you to order the rules for efficiency. IOW You can put the more requested location first.

Justin