Forum Moderators: phranque

Message Too Old, No Replies

Redirect from Old to New Site

         

quipdigital

4:12 pm on May 15, 2008 (gmt 0)

10+ Year Member



I'm trying to redirect an old dynamic link to a new dynamic link. We've got some old links still indexed in google that I want to take advantage of.

I've got:

RewriteRule ^Merchant2/merchant.mvc?Screen=PROD&Product_Code=([A-Za-z0-9_-]+)$ /mm5/merchant.mvc?Screen=PROD&Product_Code=$1

I'm sure I've got to just have a simple problem, but I can't figure it out. Also I can't just redirect all requests to Merchant2, I just need it for this specific type of link.

I've looked at this post, but it didn't seem to answer my question: [webmasterworld.com...]

Thanks in advance for your help.

Dustin

jdMorgan

8:19 pm on May 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You must use a RewriteCond to test and create a back-reference to a query string:

RewriteCond %{QUERY_STRING} ^Screen=PROD&Product_Code=([A-Za-z0-9_\-]+)$
RewriteRule ^Merchant2/merchant.mvc$ /mm5/merchant.mvc?Screen=PROD&Product_Code[b]=%1[/b] [L]

Query strings are not part of a URL, they are data attached to a URL to be passed to the resource at that URL.

Jim

quipdigital

9:13 pm on May 15, 2008 (gmt 0)

10+ Year Member



Jim,

Thanks for the reply, but when I added that the whole site started throwing up 500 errors. Do I have it placed incorrectly in the file possible? Here's my full code:


DirectoryIndex /mm5/merchant.mvc?
ErrorDocument 404 http://www.example.com/store/error.html
ErrorDocument 403 http://www.example.com/store/error.html
Redirect /status https://www.example.com/mm5/merchant.mvc?Screen=OLST
Redirect /p/ http://www.example.com/mm5/merchant.mvc?Screen=PROD&Product_Code=
Redirect /c/ http://www.example.com/mm5/merchant.mvc?Screen=CTGY&Category_Code=
Redirect /s/ http://www.example.com/mm5/merchant.mvc?Screen=SRCH&Search=
Redirect /sc/ http://www.example.com/mm5/merchant.mvc?Screen=
Redirect /gh http://www.example.com/mm5/merchant.mvc?Screen=PROD&Affiliate=gh&Product_Code=HANDYBAR
Redirect /ez http://www.example.com/mm5/merchant.mvc?Screen=PROD&Affiliate=ez&Product_Code=KE100
RewriteEngine On
RewriteCond %{QUERY_STRING} ^Screen=PROD&Product_Code=([A-Za-z0-9_\-]+)$
RewriteRule ^Merchant2/merchant.mvc$ /mm5/merchant.mvc?Screen=PROD&Product_Code=%1 [L]
RewriteRule ^store/([A-Za-z0-9_-]+)-p-([^.]+)\.html$ /mm5/merchant.mvc?Screen=PROD&Product_Code=$1&Category_Code=$2
RewriteRule ^store/([A-Za-z0-9_-]+)\.html$ /mm5/merchant.mvc?Screen=USL&Code=$1 [T=application/x-httpd-mv]
RewriteRule ^site/([A-Za-z0-9_-]+)\.html$ /mm5/merchant.mvc?Screen=USL&Code=$1 [T=application/x-httpd-mv]
RewriteRule ^site/prods/([A-Za-z0-9_-]+)\.html$ /mm5/merchant.mvc?Screen=SRCH&Search=$1 [T=application/x-httpd-mv]

All the redirects in the beginning of the file are leftover from a while ago and we've left them there because a few people still use the old links.

Thanks for your help.

Dustin

jdMorgan

9:20 pm on May 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What's in your server error log?

Also, be aware that your ErrorDocument directives will both produce 302-redirects, instead of returning the correct server error status. This is a serious problem if you're trying to rank is search engines. Use:


ErrorDocument 404 /store/error.html
ErrorDocument 403 /store/error.html

See the Apache ErrorDocument documentation for details.

Jim

quipdigital

9:37 pm on May 15, 2008 (gmt 0)

10+ Year Member



Here's what was in the error log:

[Thu May 15 14:05:21 2008] [alert] [client 24.178.49.91] /var/www/vhosts/example.com/httpdocs/.htaccess: RewriteCond: bad flag delimiters, referer: http://www.example.com/ 

jdMorgan

12:06 am on May 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Most likely a typo'ed character or an un-escaped space somewhere in the code -- I don't see it in what you posted above.

The 'flag' being referred to is one of the RewriteRule or RewriteCond flags, as denoted by [f] at the right end of the line -- for example, [L] or [T=application/x-httpd-mv]. The delimiter for this flag is the space that precedes it. The only other spaces allowed in the line are the one after the directive (e.g. RewriteRule) and the one after the regular-expressions pattern. So, you get three spaces per line, basically. No space should follow [f], either.

If you were to type "Product_Code" as "Product Code" in a regex pattern, it would cause this problem.

If you can test on an off-line server, try commenting-out each line in turn by putting a "#" in front of it. This would help narrow down the problem.

Jim

jdMorgan

12:07 am on May 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One more thought: Make darn sure you're using a plain-text editor and not a word-processor or HTML editor to edit this file! :)

Jim

quipdigital

4:33 pm on May 16, 2008 (gmt 0)

10+ Year Member



Thank you for your help. I have to set this up offline to do the testing.