Forum Moderators: phranque

Message Too Old, No Replies

Yet another rewrite problem

Similar URLs

         

JackR

4:17 pm on Oct 26, 2011 (gmt 0)

10+ Year Member



Old URL http://www.example.com/widget.html

New URL http://www.example.com/widget-widget.html


RewriteRule ^widget\.html? http://www.example.com/widget-widget.html [R=301,L]



Gives a loop. I guess the ^ is the problem. What do I use to match only the older URL with the new URL?

lucy24

8:56 pm on Oct 26, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



In fact the ^ is necessary because it constrains your requests to ones that begin in "widget.html". If you didn't have it, you would get a loop, because then it would include requests that already say "widget-widget. html".

The loop has to be coming from somewhere else.

Is there any possibility of something after the "html"? That is, other than query strings, which don't count. Can't hurt to use an ending anchor $ in any case.

JackR

9:09 pm on Oct 26, 2011 (gmt 0)

10+ Year Member



No, there is nothing at all after the .html

Old page is widgets.html, new is widgetsnew.html

But rewriting widgets| also blocks |widgetsnew!


There's another similar problem with this one:


http://www.example.com/banners


Is the non-existent URL being reported in Webmaster Tools.

If I add |banners to the rewriterule, it blocks all images sitewide in the /banners folder!

How do I return a .410 for only /banners as a URL?

g1smd

10:56 pm on Oct 26, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Your original code should have worked; there's obviously another rule affecting things.

Turn MultiViews off if it is on.

JackR

11:27 pm on Oct 26, 2011 (gmt 0)

10+ Year Member



MultiViews is not on

When I add widget| back into the .htacess file, widget-new.html is being blocked as follows:

The web page at http://www.example.com/widnet-new.html has resulted in too many redirects. 




The line is as follows:

RewriteRule ^widget-guide|widget-help-page|widget|widget-folder/widgets\.html? http://www.example.com/new-widget-page.html [R=301,L]

JackR

11:35 pm on Oct 26, 2011 (gmt 0)

10+ Year Member



Bizarrely enough, I fixed it by changing the entry for 'widget|' to 'widget.html|'.

Wonder why it wasn't matching without the .html ...

g1smd

11:43 pm on Oct 26, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Very simply the ^ "begins with" anchor applies only to ^widget-guide

You have ^widget-guide OR widget-help-page OR widget OR widget-folder/widgets\.html OR widget-folder/widgets\.htm

You can request any extension for all of the pages, except for any ending in widgets\.html or widgets\.htm

You need parentheses in the right place to make the rule work as intended. You do NOT need to duplicate the \.html part.

Note that
widget-this|widget-that|widget-other
simplies to
widget-(this|that|other)
too.

[edited by: g1smd at 11:48 pm (utc) on Oct 26, 2011]

JackR

11:45 pm on Oct 26, 2011 (gmt 0)

10+ Year Member



So I need to substitute widget| for ^widget| ?

g1smd

12:23 am on Oct 27, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



No. See above.

lucy24

3:55 am on Oct 27, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This is your original pattern:

^widget-guide|widget-help-page|widget|widget-folder/widgets\.html?


Paste it into an empty text document and globally replace all pipes | with [OR] and a line break. That should make it easier to understand what's going on.

JackR

4:29 am on Oct 27, 2011 (gmt 0)

10+ Year Member



Thanks Lucy. Nietzsche couldn't have explained it more clearly!

Working fine ... at last!

g1smd

6:21 am on Oct 27, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Let's see that working code.