简体   繁体   English

.htaccess在文件扩展名后删除斜杠

[英].htaccess remove trailing slash after file extension

I have some external links to my site that referrer to pages with a file extension and a trailing slash after that eg 我有一些指向我网站的外部链接,这些链接引用了带有文件扩展名和后跟斜杠的页面,例如

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

I can not change these links, but I would like to 301 redirect those links to this format instead: 我无法更改这些链接,但是我想将这些链接重定向到301:

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

I've tried this, but it doesn't work: 我已经尝试过了,但是没有用:

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

Any help is appreciated. 任何帮助表示赞赏。

Try this in your /.htaccess file 在您的/.htaccess文件中尝试

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM