.htaccess remove trailing slash after file extension

匿名 (未验证) 提交于 2019-12-03 09:06:55

问题:

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/

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] 

Any help is appreciated.

回答1:

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] 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!