Forum Moderators: phranque

Message Too Old, No Replies

clean urls - rewrite x.php?id=1 to x/1.html is easy enough

but how about coming the other way round?

         

sabai

1:10 pm on Mar 7, 2004 (gmt 0)

10+ Year Member



On my shopping cart, I've re-written my product view pages to be friendly URLs....

product.php?product=213

using


RewriteEngine on
RewriteRule ^product/(.*)\.html /product\.php\?product=$1

becomes


product/213.html

Now I'd like to use rewritecond so that if product.php?product=213 is requested, it redirects to product/213.html, but only if the request for product.php isn't a rewrite in the first place... I am sure this is possible. I hope I've explained this satisfactorily

The reason is to stop search engines listing the page twice...

thanks for any replies...

Symbios

10:19 pm on Mar 7, 2004 (gmt 0)

10+ Year Member



bump

One of you guys must know how to do this, I'd like to know as well as Sabai

Symbios

10:34 pm on Mar 7, 2004 (gmt 0)

10+ Year Member



I'd like to add to the question.

Instead of displaying;

product/213.html

Is there a way to use the rewrite to write the url as;

product/whatever-is-in-title-tag-213.html

sabai

8:31 pm on Mar 9, 2004 (gmt 0)

10+ Year Member




RewriteCond %{IS_SUBREQ}!^true$
RewriteCond %{QUERY_STRING} ^product=(\d*)(.*)
RewriteRule ^product\.php.* /product/%2\.html\? [R]

I thought I could do something like this, but it doesn't work because IS_SUBREQ doesn't do what I hoped it might. I tried using HTTP_FORWARDED too without results. If anybody has any hint as to what to do I'd love to hear from you... There must be some way to stop it from infinate looping... anybody?

sabai

7:11 pm on Mar 10, 2004 (gmt 0)

10+ Year Member



Well, there doesn't seem to be a mod rewrite solution... Putting this is product.php works, but I'd much rather have done it with mod rewrite.


if (! substr_count( $_SERVER['REQUEST_URI'],"/product/" ) ) {
header("Location: /product/$product_id.html");
exit();
}

It seems like you can't use the mod rewrite equivalent...


RewriteCond %{REQUEST_URI}!.*/product/.*

Anyobdy know why?

closed

5:06 am on Mar 12, 2004 (gmt 0)

10+ Year Member



You'd have to look at the code around it. If you had only the
RewriteEngine on
line, and then the line you mentioned, it would be valid. It wouldn't do anything, but you wouldn't get any error messages either.