homepage Welcome to WebmasterWorld Guest from 54.204.94.228
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / WebmasterWorld / Webmaster General
Forum Library, Charter, Moderators: phranque

Webmaster General Forum

    
htaccess - redirecting a URL with "?" in it
KevinC

10+ Year Member



 
Msg#: 4669079 posted 4:47 am on May 7, 2014 (gmt 0)

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:

http://www.example.com/red-widget.html?price=1%2C250

to

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


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]

 

phranque

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



 
Msg#: 4669079 posted 7:24 am on May 7, 2014 (gmt 0)

what type of web server?

what have you tried?
what response are you getting?

lucy24

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



 
Msg#: 4669079 posted 7:28 am on May 7, 2014 (gmt 0)

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.

KevinC

10+ Year Member



 
Msg#: 4669079 posted 10:34 pm on May 7, 2014 (gmt 0)

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.

lucy24

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



 
Msg#: 4669079 posted 3:51 am on May 8, 2014 (gmt 0)

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?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / WebmasterWorld / Webmaster General
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved