Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule - simple question

         

olegin

4:46 am on Mar 23, 2008 (gmt 0)

10+ Year Member



Hi there,
I'm first time writing to this great community, so please let me know you I'm doing something wrong.....

The story:

I'm using the following line to redirect visitors from "http://www.domain.com/targetfolder/foo" to "http://www.domain.com/linking/link.php?keyword=foo" :

###############
RewriteRule ^targetfolder/([-_A-Za-z0-9]+)$ linking/link.php?keyword=$1
###############

As you can see: "targetfolder" and "linking" folders both located in the root directory.

But sometimes, somehow Joomla generated URL looks like: "http://www.domain.com/anotherfolder/targetfolder/foo" and definitely visitor getting Error 404 Page clicking on that link.

My question:

How RewriteRule should looks like to catch any URLs with "targetfolder" inside and redirect to "linking" folder?

Please advice

Thanks in advance

jdMorgan

4:15 pm on Mar 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The simple answer is to change your rule:

RewriteRule [b]^([^/]+/)?t[/b]argetfolder/([-_A-Za-z0-9]+)$ /linking/link.php?keywor[b]d=$2 [L][/b]

The problem is that this results in duplicate content --the same page appearing at more than one URL-- and that can cause ranking problems in search engines. You will be much better off if you fix Joomla instead, so that it does not produce incorrect links on your pages.

Jim

olegin

4:51 pm on Mar 23, 2008 (gmt 0)

10+ Year Member



Thank you very much, Jim

Totally agree with you. I'm working on duplicate content issue, but at the same time, I decided (just in case) to have a generic RewriteRule to cover all possible cases ... Am I right?

BTW, Your rule is working perfect, just small wish: is it possible to change RewriteRule to open "_blank" page ( I don't want to lose a visitor)?

Thank you very much again for your support

Oleg

jdMorgan

5:32 pm on Mar 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you want to allow ([-_A-Za-z0-9]+) to be blank, change "+" to "*".

See the references cited in our forum charter [webmasterworld.com] for more information on regular expressions.

Jim

olegin

5:42 pm on Mar 23, 2008 (gmt 0)

10+ Year Member



Thank you very much, Jim for quick response. I'll try it asap
...and definitely I'll read forum charter, sorry I didn't do this before :)