Need Help with .htaccess redirect one url to another with code

2 replies
Need Help with .htaccess redirect one url to another with code I can not post links on this forum yet so bear with me imagine a domain before the directories

ok here is the problem I have a site directory that I am redirecting to another site

example old site
/olddir/viewvideo?id=gPOfurmrjxo
I need it to redirect to the new site/directory exactly the same
newsite .com/newdir/viewvideo?id=gPOfurmrjxo

I am using the following .htaccess code




RewriteEngine On
RewriteRule ^([a-z]+) newsite .com/newdir/ [R,NC,L]

it iis redirecting the folder traffic to the new site only it redirects it like so

newsite .com/newdir/?id=gPOfurmrjxo

which cause's errors since it is missing the "viewvideo" in the url

should redirect like this
newsite .com/newdir/viewvideo?id=gPOfurmrjxo

but for some reason everything before the ? is deleted there are other quieres like

newsite .com/newdir/index?id=gPOfurmrjxo
newsite .com/newdir/search?id=gPOfurmrjxo

but the same thing when it is redirected it send directly to

newsite .com/newdir/?id=gPOfurmrjxo

without the viewvideo or index or search ect.

what can I do to the .htaccess to recognize the words before the ? and carry it over exactly the same to the new domain or directory
#code #htaccess #redirect #url
  • Profile picture of the author jlandells
    You might be better off doing this in PHP. Apart from being easier to get your head around what's going on, you can make it more flexible so that you don't have to hard code the parameters in your .htaccess file.

    -John.
    {{ DiscussionBoard.errors[4283764].message }}
  • Profile picture of the author AdWorkMedia
    Agree, you could read the variables in the incoming URL string and set a dynamic PHP 301 redirect to the new page, while saving the SEO juice.

    Redirect in PHP like so:
    Code:
    <?
    Header( "HTTP/1.1 301 Moved Permanently" ); 
    Header( "Location: http://www.NEW_URL.com" ); 
    ?>
    Signature


    AdWork Media » Global Affiliate Network & Content Locking Solutions

    Custom Platform, Flexible Lockers, Offers For Every Country
    {{ DiscussionBoard.errors[4283964].message }}

Trending Topics