网站重新设计后,我有几个页面需要重定向.一切都保留在同一个域中,只是重组和/或重命名了一些内容.它们的形式如下:
After a site redesign, I've got a couple of pages that need to be redirected. Everything is staying on the same domain, just a couple of things have been reorganised and/or renamed. They are of the form:
/contact.php
/contact.php
现在:
/contact-us.php
/contact-us.php
使用 .htaccess 文件,我添加了这一行,这是我最推荐的:
Using the .htaccess file, I've added this line, which is the one I find recommended most:
RedirectMatch 301 /contact.php /contact-us.php这基本上没问题 - 它可以完成工作 - 问题是,它还重定向:
This is mostly fine - it does the job - the problem is, it also redirects:
- /team1/contact.php
- /non-existant-folder/contact.php
有没有办法指定我只想重定向根目录中的contact.php?
Is there a way of specifying that I only want to redirect the contact.php in the root?
推荐答案RedirectMatch 使用与 URL 路径匹配的正则表达式.并且您的正则表达式 /contact.php 仅表示 包含 /contact.php 的任何 URL 路径,但不只是 包含 任何 URL 路径正是 /contact.php.所以在字符串的开头和结尾使用锚点(^ 和 $):
RedirectMatch 301 ^/contact.php$ /contact-us.php更多推荐
.htaccess 301 单页重定向
发布评论