简体   繁体   中英

Redirect from specific page to external website

I have a link with a query string that I need to redirect to an external website using .htaccess

for example:

 http://check.local.com/mod/ctxcatalog/course.php?id=187

to

https://google.com

I have tried everything with mod rewrite and 301 redirects. Can anyone help me out?

To redirect a specific page ,you can use :

RewriteEngine on

RewriteRule ^page\.php$ http://Google.com/ [NC,L,R]

The rule above will redirect http://example.com/page.php to http://example.com/ including any querystrings from the old uri to the new one. ie: /page.php?querystring => http://example.com/?querystring .

If you want to redirect a specific page with a specific query perameter, you can use the following

RewriteEngine on

RewriteCond %{QUERY_STRING} ^id=123$
RewriteRule ^page\.php$ http://example.com/? [L,R]

This will redirect /page.php?id=123 to http://example.com/ and it does not append the old querystring id=123 to the destination url http://example.com/ as we have discarded them using the ? in Rule's target url http://example.com/ ? .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM