Forum Moderators: phranque

Message Too Old, No Replies

Redirecting Double slash to single slash sub-directory

         

motorhaven

5:05 pm on Nov 21, 2011 (gmt 0)

10+ Year Member Top Contributors Of The Month



I'm getting page requests in the form:

/forums//showthread.php?some parameters here

I'd like to redirect them to a properly formatted URL. For example:

www.examplesite.com/forums//showthread.php?t=7293

redirect this to:

www.examplesite.com/forums/showthread.php?t=7293

I've tried:
RewriteRule ^/forums//showthread.php /forums/showthread.php [R=301,QSA,L]

But that doesn't work.

g1smd

5:48 pm on Nov 21, 2011 (gmt 0)

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



RewriteRule cannot see the leading slash of requests so pattern with leading slash will never match.

Escape literal periods in RegExpatterns.

Target URL needs to also have protocol and domain added.

QSA flag is not needed as that is the default operation.

lucy24

10:54 pm on Nov 21, 2011 (gmt 0)

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



There is a cluster of recent questions about this same multiple-slash issue. They are generally mixed in with unrelated questions, so the threads meander a bit. But try Forums search and you should come up with some exact wordings.

Unless you mean that your specific example is the only malformed request you're getting. In that case, stick with a specific rule.

[QSA] is only needed when you have created a new query that you need to add to the existing query instead of replacing it. If you don't say anything about a query string one way or the other, mod_rewrite will quietly set it aside and then reattach it when done.

tangor

11:35 pm on Nov 21, 2011 (gmt 0)

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



I've found that most malformed URI requests are from scammer/scrapers and thus allow them to die the little death, ie. don't worry about them as there is no benefit to correct these and at best are bandwidth costs if redirected. Pick and chose, of course, this is just what I do.

motorhaven

12:56 am on Nov 22, 2011 (gmt 0)

10+ Year Member Top Contributors Of The Month



These are coming in from Googlebot, to the tune of 10,000 to 20,000 requests/day. Its left-over from the previous owner of the site who at some point had a misconfiguration. I was brought in take care of SEO issues.

The reason I ask is I tried all my standard rewrite tries, about 5 different ways, searched here, etc. Nothing seems to work. Everything redirects, but they all end up as showthread.php?t= with nothing after the "t=".

I've done some digging and as best as I can determine VBSEO is mucking up the process so I'm going to take a closer look to see if there's a 2nd redirect going on in addition to mine.

lucy24

3:10 am on Nov 22, 2011 (gmt 0)

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



The reason I ask is I tried all my standard rewrite tries, about 5 different ways, searched here, etc. Nothing seems to work. Everything redirects, but they all end up as showthread.php?t= with nothing after the "t=".

I've done some digging and as best as I can determine VBSEO is mucking up the process so I'm going to take a closer look to see if there's a 2nd redirect going on in addition to mine.

Well, don't blame mod_rewrite. It doesn't touch the query string unless you clearly and unambiguously tell it to. That's, ahem, "clearly and unambiguously" in Apache, which does not always behave like English.

Having two entirely different entities mixed up in redirection is probably even worse than combining mod_rewrite and mod_alias in the same htaccess ;)

Quick edit: I assume all the bad links have been fixed. But how long ago? If it was more than a few months, it may be simpler just to issue a generic 410 for anything with the //+ configuration, because anything SEO-related has already happened. Not 100% honest, since they never really existed in the first place, but 410 may clean up faster than 404.

motorhaven

3:27 am on Nov 22, 2011 (gmt 0)

10+ Year Member Top Contributors Of The Month



Well, I don't have much choice (two different entities). The forum's URLs have been set up using VBSEO, and VB plug-ins have their own set off rules in .htaccess as well and I came into this after the fact.

I'm the guy who has to clean this up eventually, but I do like challenges. :) I have pretty much 100% confirmed its something to do with VBSEO - I've tried a redirect on a test site without VBSEO turned off so it works... now I just have to figure out exactly what VBSEO is doing. I'll post progress.