I want to redirect http://www.example.com/findyourname/ to http://www.newexample.com./findyourname/

http://www.example.com is a wordpress site , so when accessing http://www.example.com/findyourname/ it fetches various pages as per log file

    "GET /wp-content/uploads/2017/09/green.jpg HTTP/1.1" 304 - "http://www.example.com/findyourname/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0" 518 "-" "Cookies:-" -
    "GET /wp-content/uploads/2017/09/example-banner-template_11974.jpg HTTP/1.1" 304 - "http://www.example.com/findyourname/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0" 445 "-" "Cookies:-" -
    "GET /wp-content/uploads/2016/05/example-logo-black.png HTTP/1.1" 304 - "http://www.example.com/findyourname/" 

I wrote the below rules in .htaccess but I think this is not going to work .

    RewriteRule ^/findyourrep/  http://www.newexample.com/findyourname/ [NC,R=302,L]      

Any suggestions please

RewriteRule ^/findyourrep/  http://www.newexample.com/findyourname/ [NC,R=302,L]

In .htaccess the URL-path matched by the RewriteRule pattern does not have a slash prefix, so the regex should be ^findyourrep/ instead. The pattern ^/findyourrep/ will simply fail to match.

You also need to make sure this redirect goes before the WordPress front-controller, near the top of the .htaccess file.

Also note that the pattern ^findyourrep/ matches any URL that starts /findyourrep/, not just that single URL - is that the intention? Everything is then redirected to a single URL at the new host.

Providing example.com and newexample.com don't point to the same place, then that should be all that's required.

| improve this answer | |
  • Thanks again :) Working – Zama Ques Jul 24 '19 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.