开发者

Apache: redirecting users, but keep same path?

开发者 https://www.devze.com 2023-01-11 23:42 出处:网络
I want to be able to redirect users to a different TLD but keep the same path: For example if the user goes to:

I want to be able to redirect users to a different TLD but keep the same path:

For example if the user goes to:

examp开发者_如何学运维le.com/cars/10

Using apache how can I redirect the user to something like:

my_new_site.com/cars/10


If you have mod_rewrite enabled on your server, you can place this into your .htaccess file.

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteCond %{HTTP_HOST} ^example\.com$
  RewriteRule ^(.*)$ http://my_new_site.com/$1 [R=301,L]
</IfModule>


use a 302 redirect in your config:

<VirtualHost *:80>
  ServerName example.com
  Redirect /cars http://my_new_site.com/cars/
</VirtualHost>

If you need more flexibility, you can use mod_rewrite, and then use those rewrites:

RewriteEngine on
RewriteRule ^/(.*)$ http://my_new_site.com/$1 [NC]

There's a nice documentation at apache.org.

0

精彩评论

暂无评论...
验证码 换一张
取 消