.htaccess redirect for all .asp pages

Hi

I’m struggling with a redirect I need to add to my .htaccess file.

I’ve got a bunch of pages of the form

http://www.domain.com/m.asp?m=999999XX

that I want to redirect to domain. com but I’ve not found a rule yet that does that.

I’ve tried

Redirect 301 /m\\.asp?m=999999XX http://www.domain.com

and then I got adventurous and tried

RewriteCond %{HTTP_HOST} !^www\\.domain\\.com/.\\.asp.$ [NC]
RewriteRule .? http://www.domain.com [R=301,L]

but neither work. As I don’t understand why they don’t work, I’m not sure what I need to change.

Can anyone help?

Hoop,

ASP pages on an Apache server? Horrors! It’s my understanding that the modules required for ASP are not fully compatible with the M$ implementation on M$ servers (which have a less then optimal “copy” of mod_rewrite implemented, too).

First, the Redirect is a mod_alias redirection (not mod_rewrite). I don’t believe that mod_alias (at least for a Redirect statement) can even examine the query string.

Second, your

RewriteCond %{HTTP_HOST} !^www\\.domain\\.com/.\\.asp.$ [NC]
RewriteRule .? http://www.domain.com [R=301,L]

will work to enforce the www in the domain but only redirects to the DirectoryIndex (index.php default.asp whatever).

If all you’re trying to do is redirect m.asp?m=999999XX to the site’s default page (and the page is already identified by a DirectoryIndex statement in httpd.conf or httpd-vhosts.conf or .htaccess):

RewriteEngine on
RewriteCond %{QUERY_STRING} ^m=999999XX$
RewriteRule .? http://www.example.com/? [R=301,L]
# Note:  The trailing /? in the redirection kills the query string
# which prevents looping

Regards,

DK

LOL, I bought the domain recently and only discovered its dark secret from the missing links reported in Google Webmaster Tools :smiley:

The rule you gave worked perfectly for the one specific URL I wanted to redirect. I have a few others of the same form, but different parameters for the m=999999XX bit, but I found that

RewriteEngine on
RewriteCond %{QUERY_STRING} ^m=.*$
RewriteRule .? http://www.domain.com/? [R=301,L]

seems to work on all of them. Hopefully I haven’t broken something else by using that!

Thanks very much for your help :slight_smile:

hoop,

Hmmm, are you using Apache or trying to plug away on a M$ kludge? It MUST be Apache if you’re in this forum board! :tup:

.* is a VERY DANGEROUS bit of regex (to use without knowing what you’re really doing). I knew that 999999XX was probably NOT what you really wanted but, because that’s what you presented (NOT nine digits followed by two UPPERCASE letters), that’s what I specified above. If you really don’t care what m’s value is, then ^m= should be sufficient (without the end anchor). Of course, if you needed to capture the value, then ^m=([0-9]{6}[a-zA-Z]{2})$ will capture six digits followed by two characters. Once that’s done in your RewriteCond statement, you can use it in following RewriteCond and RewriteRule statements WITHIN THAT BLOCK STATEMENT as %1.

RewriteEngine on
RewriteCond %{QUERY_STRING} ^m=.*$
RewriteRule .? http://www.domain.com/? [R=301,L]

Did that clarify anything for you? Did you catch that the /? after the domain will send to the DirectoryIndex AND kill the query string?

Regards,

DK

Ha ha, to tell the truth I haven’t a clue what I’m doing and should be led quietly away from this file. ^m= worked beautifully.

Course I did :smiley:

Thanks DK!

hoop,

Aw, be careful, mate, or we’ll be making an expert out of you yet! :wink:

Regards,

DK