微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

.htaccess规则,将旧的未到地址redirect到新地址

下面是在博客上看我的旧post地址的方法

subdomain.domain.com/view/1310/article-title/

当访问者来自Google这样的地址时,我希望它被redirect,如下所示:

http://www.domain.com/article-title/

我需要指定一些关于旧的/第一个链接的细节:

子域 ,是一个variables

查看 ,是一个固定的词

1230 ,cand是任何数字/编号

我试过这个:

清理URLredirect循环

在mod_rewrite正则expression式中使用escape(。)字符

将http和https请求redirect到新主机

htaccess重写规则以无限循环结束

Nginx重写从“if”转换为“try_files”

Options +FollowSymLinks RewriteEngine On RewriteCond %{HTTP_HOST} subdomain.domain.com $ [NC] RewriteRule ^/view/(*)/(.*)$ http://www.domain.com/$2 [R=301,L]

导致一个大500的错误

网站是一个wordpress cms的裁决。

提前致谢!

在Michael Berkowski的回答之后添加。 我目前的wp规则是:

<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index.PHP$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.PHP [L] </IfModule>

为什么我的.htaccess文件redirect到完整的服务器path而不是相对path?

将?lang = enstringredirect到子文件夹/ en

使用Apache的Flowplayer安全stream式传输

htaccess如何将子目录redirect到外部URL

htaccess将http://和http:// wwwredirect到https://可以很好地与子域配合使用

500错误是(*)的结果,其中* (零个或多个)没有任何前缀作为限定符。 你可能打算使用(.*)但是你真正需要的是[^/]+把所有的字符都放到下一个/

Options +FollowSymLinks RewriteEngine On # Slight modification of the subdomain - must escape . RewriteCond %{HTTP_HOST} subdomain.domain.com$ [NC] # Note this may need to be ^view/ instead of ^/view # In htaccess context the leading / should probably not be there RewriteRule ^/view/([^/]+)/(.*)$ http://www.domain.com/$2 [R=301,L]

以上内容专门针对subdomain.domain.com ,但是由于您指定的是可变的,因此可以使用它来获取除www.domain.com之外的所有子域:

Options +FollowSymLinks RewriteEngine On # Matches all subdomains except www. RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC] RewriteRule ^/view/([^/]+)/(.*)$ http://www.domain.com/$2 [R=301,L]

如果没有这个,发布任何其他的重写规则(因为你提到这是wordpress,我希望你有其他的规则),因为顺序可能是重要的。

更新包含wordpress规则:

<Ifmodulee mod_rewrite.c> RewriteEngine On RewriteBase / # The new rules handle the subdomain redirect... RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC] RewriteRule ^view/([^/]+)/(.*)$ http://www.domain.com/$2 [R=301,L] # After which wordpress does its internal redirection RewriteRule ^index.PHP$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.PHP [L] </Ifmodulee>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐