You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Edd Dawson <ed...@gmail.com> on 2008/03/13 11:57:06 UTC

[users@httpd] 301 redirect puzzle

I have a bit of a 301 puzzle here that I can't quite solve, and maybe
someone can help me out.

I have 3 pages:

page 1= /merchant.php?i=1
page 2= /merchant.php?i=1&j=2
page 3= /merchant.php?=1&j=2

I want to us a combination of url-rewriting and 301 redirects so they so a
request to the old page url's are forwarded to:

page 1= /merchantname
page 2= /merchantnameproductname1
page 3= /merchantnameproductname2

and when these new url's are reached they actually are generated behind the
scenes by the old urls.

Now I thought I had it with the following code in my Apache config:

RewriteRule ^/merchantnameproductname2 /merchant\.php\?i\=1\&j\=2
[PT,QSA,NS,NE]
RewriteCond %{REQUEST_URI} ^(.*)merchant\.php(.*)$
RewriteCond %{QUERY_STRING} ^i\=1\&j\=2$
RewriteRule ^(.*)$ /merchantnameproductname2? [R=301,L]

RewriteRule ^/merchantnameproductname1 /merchant\.php\?i\=1\&j\=1
[PT,QSA,NS,NE]
RewriteCond %{REQUEST_URI} ^(.*)merchant\.php(.*)$
RewriteCond %{QUERY_STRING} ^i\=1\&j\=1$
RewriteRule ^(.*)$ /merchantnameproductname1? [R=301,L]



RewriteRule ^/merchantname /merchant\.php\?i\=66 [PT,QSA,NS,NE]
RewriteCond %{REQUEST_URI} ^(.*)merchant\.php(.*)$
RewriteCond %{QUERY_STRING} ^i\=1$
RewriteRule ^(.*)$ /merchantname? [R=301,L]


Now what happens is that the rewrite and 301 redirect works for page1, but
page2 and page3 the 301 works and I get directed to the correct new page
url, but the underlying rewrite always creates the content for page2, never
page3

I am a bit stuck.. can anyone see the flaw?

Thanks.

Re: [users@httpd] 301 redirect puzzle

Posted by Joshua Slive <jo...@slive.ca>.
On Thu, Mar 13, 2008 at 6:57 AM, Edd Dawson <ed...@gmail.com> wrote:

>
>  RewriteRule ^/merchantnameproductname2 /merchant\.php\?i\=1\&j\=2
> [PT,QSA,NS,NE]

There seems to be a bunch of superfluous backslash escaping going on
here. Why "\?" and not simply "?" for example? That may be messing up
the resulting query string and thereby screwing up your script.

>  I am a bit stuck.. can anyone see the flaw?

Other than that, use the RewriteLog to see what is going on..

Joshua

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org