Forum Moderators: phranque

Message Too Old, No Replies

Redirecting and passing source as a param

         

DaveQ

4:54 pm on Mar 22, 2011 (gmt 0)

10+ Year Member



Hi,

I need to set up a website redirection that will convert:

www.mydomain.com/myfolder*/mypage*.html

to

www.mydomain.com/redirect.php?source=myfolder/mypage.html

Can anyone advise me on the htaccess for doing this?

Thanks

g1smd

8:39 pm on Mar 22, 2011 (gmt 0)

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



There's tens of thousands of threads in this forum with similar code. What have you tried so far?

DaveQ

9:51 am on Mar 23, 2011 (gmt 0)

10+ Year Member



Sorry, I have tried searching for similar examples on this forum but without success.

Here's what I have so far in .htaccess:

Options +FollowSymlinks
RewriteEngine On
RewriteRule ^(.+)\.html$ /redirect.php?source=$1 [NC,R=301]

This has the outcome of redirecting: mydomain.com/test/news12.html
to: mydomain.com/redirect.php?source=news12

but I want it to redirect to:
mydomain.com/redirect.php?source=test/news12.html

so basically I'm missing the .html and the folder. What am I doing wrong?

Thanks

jdMorgan

11:27 pm on Mar 28, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Move the code to root -- it must be above the "/test" directory if you wish the rule to be able to "see" the /test part of the path. Also Include the ".html" in the parentheses if you wish to capture it.

Options +FollowSymlinks
RewriteEngine On
#
RewriteRule ^(test/.+\.html)$ /redirect.php?source=$1 [NC,R=301,L]

Jim