htaccess的mod-rewrite301重定向 [英] .htaccess mod rewrite 301-redirect

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

问题描述

我想: 与国家301重定向到目录中,例如其中不包含文件名中所有链接(不.HTML,.JPG,.PNG,的CSS):A HREF <=htt​​p://mysite.com/article相对=nofollow > http://mysite.com/article - > http://mysite.com/article/ 但是, http://mysite.com/article/article-15.html 不是重定向。 什么regulat EX pression我必须写为.htaccess添加斜线虚拟目录?

I want: all links which not contained filename (not .html, .jpg, .png, .css) redirect with state 301 to directory, for example: http://mysite.com/article -> http://mysite.com/article/ But http://mysite.com/article/article-15.html not redirects. What regulat expression I must write to .htaccess for adding slash to virtual directories?

推荐答案

我认为以下可能的工作:

I think the following might work:

RewriteEngine on   
RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]

当谈到mod_rewrite的我也不能肯定没有测试,但...

When it comes to mod_rewrite I can never be sure without testing though...

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

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