Forum Moderators: phranque

Message Too Old, No Replies

.htaccess Rewrite problem.

I've got a few issues hopefully someone can help solve.

         

percykwong

7:57 pm on May 18, 2012 (gmt 0)

10+ Year Member



For some odd reason, I'm getting the following urls in my wordpress install. Apparently, a plugin hosed the database and after many days of research and trial / error, I'm still at a standstill.

I'm hoping someone can help me with how to configure this.

I get incoming requests for webpages like:

Problem 1:

http://example.com/?/post-name and it needs to be rewritten to redirect to http://example.com/post-name/

(Remove the "/?/" in the url)

Problem 2:

http://example.com/[4 digit number/[2 digit number/post-name needs to be redirected to: http://example.com/post-name/

(remove all the digits and accompanying slashes prior to post-name)

Problem 3:


http://example.com/[4 digit number/[2 digit number/[2 digit number]/post-name needs to be redirected to: http://example.com/post-name/


(remove all the digits and accompanying slashes prior to post-name)

Problem 4:

http://example.com/post-name/none needs to be redirected to http://example.com/post-name/

(removing the "none" at the end of the request).

Anybody have any ideas? I'm just horrible @ regex.

TIA

lucy24

3:08 am on May 19, 2012 (gmt 0)

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



Anybody have any ideas?

Ay-yup. But you gotta start by giving it your best try so we can poke h-- er, I mean, point out ways to fine-tune it :)

The other part of the problem is hunting down the source of those spurious URLs so you don't have to keep redirecting until the cows come home. Just let the googlebot get one whiff of them and you'll be stuck redirecting forever. If the bad URLs are being inserted by WordPress after the request lands in your htaccess, all the rewrites in the world may not be able to save you.

Problem 2 and problem 3 are just one Rule-- assuming you don't have any URLs where there is supposed to be a batch of numbers in the middle. One option is

... \d{4}/(\d\d/){1,2}(.*) ...

There are other ways to say the same thing.

In all your examples, the "bad" URL has no ending slash and the "good" URL has a slash. Is this required by wordpress? Normally the final slash would be reserved for directories. Or to things that you want the user to think are directories.

percykwong

3:19 am on May 19, 2012 (gmt 0)

10+ Year Member



The ending slash is optional.

I've done the following:

in .htaccess

RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/(.*)$ [swimminginthought.com...]
RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)$ [swimminginthought.com...]

I have no idea how to do the slash and none thing.