使用 .htaccess 重定向特定 URL [英] using .htaccess redirect specific URL

查看:48
本文介绍了使用 .htaccess 重定向特定 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何像这样重定向网站:

how to redirect the website like this :

www.old.com/test.php -> www.new.com/test.php

但输入其他链接到 www.new.com/

www.new.com/test1.php -> www.old.com/test1.php
www.new.com/test2.php -> www.old.com/test2.php
www.new.com/test3.php -> www.old.com/test3.php

如果文件名没有顺序怎么办,像这样:

How about if the file names are not in sequence, like this:

www.new.com/home.php -> www.old.com/aiej.php
www.new.com/contactus.php -> www.old.com/contact.php
www.new.com/aboutus.php -> www.old.com/aboutus.php
www.new.com/msdv.php -> www.old.com/msdv.php

只有 test.php 会重定向到 www.new.com/,其他人会重定向回 www.old.com

only test.php will redirect to www.new.com/, others redirect back to www.old.com

我更喜欢使用 .htaccess 文件.有什么建议吗?

I prefer to use .htaccess file. any suggestion?

推荐答案

在你的 .htaccess

RewriteEngine On
RewriteBase /

# Redirect test.php to new
RewriteCond %{HTTP_HOST} ^www\.old\.com$ [NC]
RewriteRule ^(test)\.php$ http://www.new.com/$1.php [R=301,L]

# Redirect test* to old
RewriteCond %{HTTP_HOST} ^www\.new\.com$ [NC]
RewriteRule ^test(.+)\.php$ http://www.old.com/test$1.php [R=301,L]

这篇关于使用 .htaccess 重定向特定 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆