Forum Moderators: phranque

Message Too Old, No Replies

RewriteMatch

Help with parameter changing

         

thegod

11:56 pm on Jan 25, 2006 (gmt 0)

10+ Year Member



yo peoples,

I am having a little trouble with regexp, its never been one of my strong points:

What I need is a rewritematch that will take cms-read_article.php?articleId=34 to /articles/read.php?article_id=34

34 being different each request

RewriteMatch ^/cms-read_article\.php\?articleId=([0-9]+) /articles/read.php?article_id=$1

is what I have at the moment that isnt working too well.

Any pointers?

jdMorgan

12:31 am on Jan 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The information in msg#2 of this thread [webmasterworld.com] will help you to solve the major problem with your code.

Jim

thegod

5:01 am on Jan 26, 2006 (gmt 0)

10+ Year Member



no it doesnt, I dont want to remove everything after the? I need to refactor it to the new format for the new egnine on the site.

jd01

5:16 am on Jan 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think what jdMorgan was showing was you will need to use a RewriteRule AND a RewriteCond %{QUERY_STRING} to do anything with information after the?

I would guess if you edited your initial syntax to something along the lines of the following you would get close:

RewriteCond %{QUERY_STRING} articleId=([0-9]+)
RewriteRule ^cms-read_article\.php$ /articles/read.php?article_id=%1

Justin

Added: I highly recommend some of the information in the library and charter (links at the top left of the pages) to help with your understanding of mod_rewrite. =)

thegod

5:22 am on Jan 26, 2006 (gmt 0)

10+ Year Member



The problem with that, is that it doesnt give the browser or the bot the same result, redirectmatch permanent would tell the "whatever" that the url has actually changed. rewrite rules keeps the url the same and apache silently does the transformation.

jdMorgan

2:41 pm on Jan 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



jd01 gave you the standard recommended internal rewrite method, and correctly discerned the purpose of my link above. Please understand that our purpose [webmasterworld.com] here is to help you to find the answers, not to write your code for you.

If you want to do an external redirect, then a small syntax change is all that is needed:


RewriteCond %{QUERY_STRING} articleId=([0-9]+)
RewriteRule ^cms-read_article\.php$ [b]http://www.example.com[/b]/articles/read.php?article_id=%1 [b][R=301,L][/b]

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim