Forum Moderators: phranque

Message Too Old, No Replies

rewrite problem

         

fzx5v0

8:56 pm on Nov 8, 2005 (gmt 0)

10+ Year Member



hi back again

I just can not get my head around mod rewrite I either get 200 where i have not matched properly or server error. I have read books on general expressions and on mod rewrite and all the recommended reading but still I can not get them to work with out help. Please can someone advise on this. Thanks
301 redirect
www.mydomain.co.uk/product_info.php?manufacturers_ id=10&products_id=98&language=en

to

http://www.example.com/product_info.php/products_id/112

the reason is that google has index all my dynamic urls

thanks in advance

[edited by: jdMorgan at 2:22 pm (utc) on Nov. 14, 2005]
[edit reason] Example.com [/edit]

jd01

12:29 am on Nov 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You will need to use THE_REQUEST to keep from looping...

There are some comments on it here [webmasterworld.com].

And you will find quite a bit more information with a search like this in your favorite SE:
THE_REQUEST php site:webmasterworld.com/forum92/

When you have something you are working with, let us know and we will help you through the details.

Justin

fzx5v0

11:07 am on Nov 14, 2005 (gmt 0)

10+ Year Member



Justin

I tried this

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /product_info\.php\?manufacturers_ id=([^&]+)&product_id=([^&]+)$
RewriteRule ^/?$ http://www.example.com [R=301,L]

but it goes into a loop and causes a 500 internal server error

thanks

[edited by: jdMorgan at 2:21 pm (utc) on Nov. 14, 2005]
[edit reason] Example.com [/edit]

jdMorgan

2:14 pm on Nov 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



301 redirect www.example.com/product_info.php?manufacturers_ id=10&products_id=98&language=en
to
http://www.example.com/product_info.php/products_id/112

Because the source and destination products_id numbers in your example are different, no general rule can be used. Here is a ruleset to handle the specific case in your example:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /product_info\.php\?manufacturers_ id=10&product_id=98
RewriteRule ^product_info\.php$ http://www.example.com/product_info.php/products_id/112? [R=301,L]

Jim

fzx5v0

6:44 pm on Nov 14, 2005 (gmt 0)

10+ Year Member



hi jim

thanks for that but that generated a 500 internal server as well

thank in advance

jd01

9:57 pm on Nov 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you copied and pasted, it looks like you have a space that needs to be escaped (or removed):

manufacturers_ id

Justin

fzx5v0

8:13 am on Nov 15, 2005 (gmt 0)

10+ Year Member



thanks

now it does not reconise the url and just does nothing

jd01

10:18 am on Nov 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The rule jdMorgan suggested only works for a single URL, are you sure you tried that one, and emptied your browser cache before you tried it?

Also, check the path to your file and make sure it is correct in both the rule and condition...

You might also try it with the regular expressions:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /product_info\.php\?manufacturers_id=([^&]+)&product_id=([^\ ]+)
RewriteRule ^product_info\.php$ http://www.example.com/product_info.php/products_id/%2? [R=301,L]

I am not seeing anything glaringly wrong with the ruleset, so I would guess it is a minor path/browser error.

Justin

fzx5v0

1:23 pm on Nov 15, 2005 (gmt 0)

10+ Year Member



the header that is sent is

HEAD /product_info.php?manufacturers_id=1&products_id=9 HTTP/1.1

and the reply is

HTTP/1.1 200 OK
Date: Tue, 15 Nov 2005 13:22:19 GMT
Server: Apache/2.0.51 (Fedora)
X-Powered-By: PHP/4.3.10
Set-Cookie: osCsid=22404516c595c81dbd7b222192f8bcd6; path=/; domain=example.com
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Connection: close
Content-Type: text/html; charset=UTF-8

that is using justin's with the general expression

[edited by: jdMorgan at 2:09 pm (utc) on Nov. 15, 2005]
[edit reason] Example.com [/edit]

fzx5v0

4:59 pm on Nov 15, 2005 (gmt 0)

10+ Year Member



i found out if I take &product_id=98 of the end ot the request line it matches the url

thanks for your help

jdMorgan

5:24 pm on Nov 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is it "product_id" or "products_id"? -- Not sure which because both are mentioned in this thread, but the pattern must match the requested URL.

Also, you could change the sub-pattern "[^&]+" to "[0-9]+" just to see if your server has some strange regex library on it that's causing it not to work with "[^&]+". This pattern simply means "one or more characters not equal to an ampersand," and should work, but if it's not matching then try something else.

Jim