Welcome to WebmasterWorld Guest from

Forum Moderators: phranque

Message Too Old, No Replies

htaccess - redirecting a URL with "?" in it



4:47 am on May 7, 2014 (gmt 0)

10+ Year Member

Sorry if this is the wrong section, I couldn't find exactly where I should put it.

So I have a bunch of urls I need to 301 redirect, they look something like this:




But I can't seem to get a simple 301 redirect to work. From researching the question mark in the URL is what's giving me trouble.

Would love a little help on this.

[edited by: phranque at 7:26 am (utc) on May 7, 2014]
[edit reason] exemplified domain [/edit]


7:24 am on May 7, 2014 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

what type of web server?

what have you tried?
what response are you getting?


7:28 am on May 7, 2014 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

Well, let's see what you've tried so far.

Hint: You will not be able to do it with mod_alias (Redirect by that name). If that's what you are currently using for your redirects, you will have to convert any existing rules to mod_rewrite syntax. It isn't safe to mix the two.

It sounds as if you haven't activated the redirects yet. So as long as you're changing things around, why not switch over to pretty URLs that don't have query strings at all?

And Psst! You may have forgotten that the magic words are "example.com". Everything else turns into a link whether you want it to or not. In the apache subforum, you definitely don't want auto-linking.

:: detour to look at specimen redirect ::

From 1%2C250 to 0%2C250 ? Darn these unilingual forums anyway. Are those commas? What are they doing in URLs? (Sure, there are times when a comma would be appropriate in a query string. But here it seems superfluous.) They're just thousands sepators, right?

Edit as shoe drops belatedly: And what's with html? On this site, are all .html extensions parsed as .php? Hm, seems like there's a lot you could change as long as you're in there.


10:34 pm on May 7, 2014 (gmt 0)

10+ Year Member

I understand the URLS are not great, but this what I'm working with and cannot change the structure.

what I've tried is

redirect 301 red-widget.html?price=1%2C250 http://www.example.com/all-red-widgets.html?price=0%2C250

I believe it is the ? and %2 that cause this standard 301 to not work.

.htaccss works fine for standard html pages, but this it does not.


3:51 am on May 8, 2014 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

You don't mean .htaccess. You mean mod_alias.

Hence the hint above ;) Search this subforum and you will find several thousand similar posts. (g1smd? Where'd you go, anyway?) Some of them come with recurring boilerplate; there's even one on converting from mod_alias to mod_rewrite when you need to change existing rules.

A further complication is that you can't say %2 in the target, because it will be interpreted as "the second capture from the most recently matched Condition" even if there was no condition, let alone a capture from it, and regardless of what text comes before or after the %2 (or % any-one-number). Here however this won't be a problem, because there will be a RewriteCond and you will be capturing from it. (You don't have to-- you can use literal text-- but mod_rewrite will expect a capture, so may as well humor it. Them. Whatever.)

I wasn't sure if the change from 1 to 0 was a typo. I now see it definitely isn't.

Do you want %2C or a comma?

Featured Threads

Hot Threads This Week

Hot Threads This Month