2

The domains below are just sample domaains. I want to redirect mydomain.com/test/ (wildcard) to google.com/dl (wildcard)

I am using this codes

RewriteEngine on
RedirectMatch 301 ^/test/.*$ https://google.com/dl

But when i access https://example.com/test/hi it redirects to https://google.com/dl , instead of https://google.com/dl/hi

How can I do it? Thanks

RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
Cyberlicious
  • 49
  • 1
  • 5

2 Answers2

2

Could you please try following, written with shown samples. Please make sure to clear your browser cache before testing your URLs.

RewriteEngine on
RewriteRule ^test/(.*)/?$ https://google.com/dl/$1 [R=301,NC,L]
RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
  • 1
    @Cyberlicious, could you please do let me know what is the link you are hitting? Also kindly do mention if you are seeing any errors etc too. – RavinderSingh13 Jan 19 '21 at 06:50
  • @Cyberlicious, This rule looks for if a URI starts from `test` then do redirect. So it will redirect like: `http://localhost:80/test/singh123` TO `https://google.com/dl/singh123` as per shown samples here. – RavinderSingh13 Jan 19 '21 at 06:53
  • 1
    Thanks, it works now. I just forgot to removed my old htaccess rules. Thank you very much! – Cyberlicious Jan 19 '21 at 07:05
  • @Cyberlicious, Your welcome, cheers and happy learning on this great forum :) – RavinderSingh13 Jan 19 '21 at 07:05
-1

You can try, you will find 100% solution, you must add below 3 lines to project's root folder .htaccess file

RewriteEngine on
RewriteBase /
RewriteRule (.*) http://www.new-domain.com/$1 [R=301,L][/php]
RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93