Welcome to WebmasterWorld Guest from 54.226.143.14

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Complex URL rewrite - assistance kindly requested

   
12:04 am on Aug 8, 2013 (gmt 0)



I'd be very grateful for some help with the following issue. I have checked extensively and been unable to find a solution elsewhere.

Where "XX" can be any single digit or double digit number from 1 through 99, I would like Apache to redirect/rewrite the following pattern:

http://mysite.com/term1/XX/some-title


to

http://mysite.com/term1/some-title


The objective here would be to strip out the XX, while preserving what is on either side of it.

"Term 1" could be one of five different, set alphabetical expressions; some title could be almost any number letter combination.

Many thanks for any advice or insights.
12:43 am on Aug 8, 2013 (gmt 0)

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



That seems pretty straightforward. Capture A, skip B, capture C, redirect to AC. So there must be some complication that you haven't mentioned. Let's see your best effort to date. In what way doesn't it work?

:: looking vaguely around for "Why we make you do it yourself" boilerplate ::
2:29 am on Aug 8, 2013 (gmt 0)

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



welcome to WebmasterWorld, davidh!


show us what you tried so we can help you fix it.
6:44 am on Aug 8, 2013 (gmt 0)

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



A related question is:

"When a user requests
http://mysite.com/term1/some-title 
is the site already set up in such a way that the correct content is shown?"
3:09 pm on Aug 10, 2013 (gmt 0)



Hello, apologies for the delay, was traveling. Thank you for your responses.

lucy24 and phranque: I have been unable to construct a redirect or rewrite that would provide the desired results. The examples that I have seen available on the internet do not address my specific need and those that I have tried to adapt have failed, and I regret to report that I did not retain the code. Mind you, I realize that my initial search cannot possibly have been exhaustive, and if, based on your own expertise, you would be so kind as to point me in the right direction, I will be glad to give it a another go and report back.

g1smd: Yes, that is correct, the site is already set up that way, thank you for asking and my apologies for failing to mention that.
7:52 pm on Aug 10, 2013 (gmt 0)



I googled for "apache redirect/rewrite any single digit or double digit number", and the first 2-3 results are good intros, which include some examples very close to what you're after.
2:49 pm on Aug 12, 2013 (gmt 0)

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



I would like Apache to redirect/rewrite...


Which would you like to do... redirect or rewrite? I assume redirect...

Something like (in .htaccess):

RewriteEngine On
RewriteRule ^(term1|term2|term3|term4|term5)/\d{1,2}/(.+)$ /$1/$2 [R=301,L]


?

(As lucy24 says... Capture A, skip B, capture C, redirect to AC.)
4:16 pm on Aug 12, 2013 (gmt 0)



Dear penders: To have delivered to me, in such a kind and understated manner, a seemingly simple line of code that works perfectly on the first try and which, as a consequence, has just made my online existence easier by orders of magnitude, is a gift for which I cannot adequately express my thanks. Many thanks, david

[edited by: phranque at 6:09 pm (utc) on Aug 13, 2013]

 

Featured Threads

Hot Threads This Week

Hot Threads This Month