301 redirecting a rewritten URL

We’re trying to 301 redirect URL’s that have already been successfully rewritten via Apache’s mod_rewrite in htaccess, but we’re having an issue.

Rewritten URL:
http://www.old_domain.com/page/AAA/BBB

Needs to redirect to this URL:
http://www.new_domain.com/newproduct.html

1st redirect attempt using:
Redirect 301 /page/AAA/BBB http://www.new_domain.com/newproduct.html

1st redirect attempt results in:
http://www.new_domain.com/newproduct.html?page=AAA/BBB

For the next attempt, we tried adding a ? to delete the existing query string:
Redirect 301 /page/AAA/BBB http://www.new_domain.com/newproduct.html?

But the result is:
http://www.new_domain.com/newproduct.html? (note the ? at the end)

Closer, but still not right…

Any suggestions? I appreciate any help.

Hello DK,

I appreciate your reply, I was hoping you’d see this post. I had previously read thru your tutorial page in your signature, which is where I got the idea to add the ? to delete the previous query. htaccess is shown below.

<Limit GET>
order deny,allow
</Limit>

AuthType Basic
Options +FollowSymlinks
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} !-s
RewriteCond %{REQUEST_URI} !\.(gif|jpg|jpeg|ico)$
RewriteRule ^page/(.*) /Merchant2/merchant.mvc?page=$1 [L]

Thanks again DK

HR,

If you’d read the tutorial, you’re already an expert!

Okay, let me comment on your code first:

<Limit GET>
order deny,allow
</Limit>
# It may be the early hour here but I don't recall a
# <limit> directive. In any case, you don't have a
# specification as to what's allowed or denied so this
# appears irrelevant.

AuthType Basic
# An AuthType statement is usually followed by a
# statement as to where it applies and what file is
# to be read for the authorization so, again, irrelevant?
Options +FollowSymlinks
# This statement is normally in the httpd.conf but
# comes under the "no harm, no foul" dictum.
RewriteEngine On
RewriteBase /
# This is to UNDO a mod_alias directive which you
# don't have so it can only confuse any issue you 
# have with your code.

RewriteCond %{REQUEST_URI} !-s
# Not a dash s in the {REQUEST_URI}???
# Is that (-s) a flag or marker that you add?
# If not, it may be another "no harm, no foul"
# but it is not needed and should not be used
# without a good reason.
RewriteCond %{REQUEST_URI} !\\.(gif|jpg|jpeg|ico)$
# GOOD! Not an image request. What about .css? .js?
RewriteRule ^page/(.*) /Merchant2/merchant.mvc?page=$1 [L]
# Is Merchant2 a variable? Are you getting
# Merchant2 from a subdirectory ({HTTP_HOST})?
# Is merchant.mvc capable of handling a null value for page?

The main thing that my tutorial was supposed to convey is to start with a good (verbal) specification of your intentions. With that, it should be easy to spot the possible pitfalls (character sets, looping, etc) and create the mod_rewrite code.

Of minor concern (to me) is the mvc extension. I’m sure you must have it accounted for with an AddType (In httpd.conf? In httpd-vhosts.conf? It wasn’t in the .htaccess!). I bring this up because mod_rewrite (as in common use) is an Apache module. IIS has its own version(s), one of which is supposed to mimic Apache’s, but please confirm that you’re using an Apache (2.x?) web server.

Regards,

DK

HR,

Congratulations on understanding that simple redirects should be done with mod_alias redirects. However, your addition of the query string is NOT being accomplished by the Redirect so you really need to show your .htaccess code for anyone to understand the origin of the problem.

Regards,

DK