.htaccess在文件扩展名后删除斜杠 [英] .htaccess remove trailing slash after file extension

查看:72
本文介绍了.htaccess在文件扩展名后删除斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些指向网站的外部链接,这些链接引用了带有文件扩展名和后跟斜杠的页面,例如

I have some external links to my site that referrer to pages with a file extension and a trailing slash after that e.g.

http://example.com/folder/page.php/

我无法更改这些链接,但我想将这些链接重定向到301:

I can not change these links, but I would like to 301 redirect those links to this format instead:

http://example.com/folder/page/

我已经尝试过了,但是不起作用:

I've tried this, but it doesn't work:

RewriteRule ^(.*)\.php\/$ /$1/ [R=301,L]

感谢您的帮助.

推荐答案

在/.htaccess文件中尝试

Try this in your /.htaccess file

RewriteEngine On
RewriteCond %{THE_REQUEST} /([^.]+)\.php/? [NC] 
RewriteRule ^ /%1/ [NC,R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /$1.php [L,NC]

这篇关于.htaccess在文件扩展名后删除斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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