Forum Moderators: phranque

Message Too Old, No Replies

RedirectMatch, same file name, files located in number of directories

RedirectMatch, same file name, files located in number of directories

         

olegin

4:42 am on Apr 3, 2008 (gmt 0)

10+ Year Member



Hi there,

I searched this forum and applied few examples but without any success, so decided to ask community for advice....

The story: I have a number of "lottery.shtml" pages located in deferent folders (based on countries)

On my new site I have to redirect all of them to one new page.

Now I'm using the following logic:
-------------------------------
Redirect 301 /UK/lottery.shtml http://www.example.com/world-lottery-association-lottery-results
Redirect 301 /DE/lottery.shtml http://www.example.com/world-lottery-association-lottery-results
Redirect 301 /SP/lottery.shtml http://www.example.com/world-lottery-association-lottery-results
Redirect 301 /FR/lottery.shtml http://www.example.com/world-lottery-association-lottery-results
......
--------------------------------
But because I have the similar logic all around my old site, my new .htaccess file quickly became a big enough, so I decided to try RedirectMatch for this (if possible).

The idea is: doesn't matter which folder, if name of requested file is "lottery.shtml" --- redirect to "http://www.example.com/world-lottery-association-lottery-results"

I tried the following but it doesn't work:

RedirectMatch 301 ^([^/]+/)?lottery.shtml$ http://www.example.com/world-lottery-association-lottery-results

Please advice

Regards,

Olegin

[edited by: jdMorgan at 4:16 am (utc) on April 4, 2008]
[edit reason] example.com [/edit]

g1smd

8:21 pm on Apr 3, 2008 (gmt 0)

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



Use RewriteRule with regex to direct this.

jdMorgan

4:20 am on Apr 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The syntax for the RewriteRule example directive you likely copied differs from that of the RedirectMatch directive. So you're missing a leading slash. Also, literal periods in regex patterns should be escaped with a preceding "\" character:

RedirectMatch 301 [b]^/([/b][^/]+/)?lottery\.shtml$ http://www.example.com/world-lottery-association-lottery-results

Jim

olegin

12:29 pm on Apr 4, 2008 (gmt 0)

10+ Year Member



Thanks g1smd, Thanks you, Jim - you're the best! ... I'll try asap

olegin

2:10 pm on Apr 4, 2008 (gmt 0)

10+ Year Member



Dear Jim,

Your code works perfect to redirect to SEF URL like http://www.example.com/world-lottery-association-lottery-results

But I didn't realize that there is lots of not SEF/original URLs.

------------------------------------------
RedirectMatch 301 ^/([^/]+/)?lottery\.shtml$ http://www.example.com/index.php?option=com_content&Itemid=129&id=176&lang=en&view=article
-------------------------------------------

I'm getting Error404, result in the browser is:

--------------------------------------

http://www.example.com/index.php%3foption=com_content/lottery.shtmlItemid=129/lottery.shtmlid=176/lottery.shtmllang=en/lottery.shtmlview=article

-----------------------------------

so, all "&" replaced with "/lottery.shtml"

Is there any way to prevent this?

Thanks in advance

Olegin