Dino Geek, try to help you

How to configure specific redirects for visitors from search engines?


To configure specific redirects for visitors from search engines, you can use various methods depending on the server and technology stack you are utilizing. This process involves setting up rules that detect incoming traffic from search engines and redirecting them to specific pages. Below is a comprehensive guide on how to achieve this:

  1. Step-by-Step Guide

  1. 1. Identify the Source of Traffic
    Determine which search engines you want to target for the redirects. Common search engines include Google, Bing, and Yahoo. This identification helps in creating precise rules.

  1. 2. Using .htaccess for Apache Servers

If you are using an Apache server, the `.htaccess` file is a straightforward way to set up the redirects. Here’s an example:

```
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^https?://(www\.)?(google|bing|yahoo)\. [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/newpage.html [R=301,L]
```

Explanation:
- `^https?://(www\.)?(google|bing|yahoo)\.` matches the referers from Google, Bing, and Yahoo.
- `^(.*)$` captures the original URL.
- `http://www.yourdomain.com/newpage.html` is where you want to redirect the user.
- `[R=301,L]` indicates a 301 permanent redirect, and `L` marks the rule as the last one to execute if conditions match.

  1. 3. Using Nginx

For Nginx, the configuration is done within the server block in the configuration file:

```
server { listen 80; server_name yourdomain.com;

if ($http_referer ~* (google|bing|yahoo)) { return 301 http://www.yourdomain.com/newpage.html; } location / { # Other configs } } ```

This rule checks if the referer contains Google, Bing, or Yahoo and then performs a 301 redirect.

  1. 4. Using PHP

If you prefer handling the redirects via PHP, here’s a sample script:

```
$referer = $_SERVER[‘HTTP_REFERER’];
if (preg_match(‘/google|bing|yahoo/i’, $referer)) { header(‘Location: http://www.yourdomain.com/newpage.html’, true, 301); exit();
}
?>
```

This script should be placed at the top of the PHP file you want to process the redirection.

  1. 5. Using JavaScript (Client-side Redirects)

Although not recommended for SEO purposes, you can use JavaScript for client-side redirects:

```

```

  1. Examples

1. Example for Apache:
- If a user lands on your site from Google and visits `www.yourblog.com/article123`, you can redirect them to `www.yourblog.com/special-offer`.

\`\`\`apache RewriteEngine On RewriteCond %{HTTP\_REFERER} ^https?://(www.)?google. [NC] RewriteRule ^article123$ http://www.yourblog.com/special-offer [R=301,L] \`\`\`

1. Example for Nginx:
- Redirecting Bing traffic to a specific landing page.

\`\`\`nginx server { listen 80; server\_name yourblog.com; if ($http\_referer ~\* bing) { return 301 http://www.yourblog.com/landing-page; } location / { # Other configs } } \`\`\`

  1. Sources

- Apache Rewrite Module Documentation: [Apache HTTPD](https://httpd.apache.org/docs/current/mod/mod_rewrite.html)
- Nginx Documentation: [Nginx](https://nginx.org/en/docs/http/ngx_http_rewrite_module.html)
- PHP.net Manual: [PHP Manual – Header Function](https://www.php.net/manual/en/function.header.php)
- Mozilla Developer Network (MDN) Web Docs: [MDN – Redirecting with JavaScript](https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirections)

These sources provide reliable and comprehensive guidance on how to set up redirects for visitors from search engines on various server technologies.


Simply generate articles to optimize your SEO
Simply generate articles to optimize your SEO





DinoGeek offers simple articles on complex technologies

Would you like to be quoted in this article? It's very simple, contact us at dino@eiki.fr

CSS | NodeJS | DNS | DMARC | MAPI | NNTP | htaccess | PHP | HTTPS | Drupal | WEB3 | LLM | Wordpress | TLD | Domain name | IMAP | TCP | NFT | MariaDB | FTP | Zigbee | NMAP | SNMP | SEO | E-Mail | LXC | HTTP | MangoDB | SFTP | RAG | SSH | HTML | ChatGPT API | OSPF | JavaScript | Docker | OpenVZ | ChatGPT | VPS | ZIMBRA | SPF | UDP | Joomla | IPV6 | BGP | Django | Reactjs | DKIM | VMWare | RSYNC | Python | TFTP | Webdav | FAAS | Apache | IPV4 | LDAP | POP3 | SMTP

| Whispers of love (API) | Déclaration d'Amour |






Legal Notice / General Conditions of Use