htaccess的code,除去延伸和补充+力斜线? [英] htaccess code to remove extension AND add+force trailing slash?

查看:227
本文介绍了htaccess的code,除去延伸和补充+力斜线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图把一些htaccess的code,它会变成 example.com/filename.php example.com/filename / (和力斜杠) - 我已经试过varous的方法,但每个没有工作完全正确,从500错误的子文件夹以问题与斜线,等等...

I'm trying to put together some htaccess code that will turn example.com/filename.php into example.com/filename/ (and force the slash) - I've tried varous approaches, but each hasn't worked quite right, from 500 errors on subfolders to issues with the trailing slash, etc...

请帮忙!

推荐答案

试试这个:

RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php
RewriteRule (.*)\.php$ /$1/ [L,R=301]

RewriteRule (.*)/$ $1.php [L]

第一条规则重定向的请求的 /富/酒吧 的.php 内外兼修 /富/酒吧 / 。第二条规则重写的请求的 /富/酒吧 / 在内部的 /富/酒吧 的.php

The first rule redirects requests of /foo/bar.php externally to /foo/bar/. And the second rule rewrites requests of /foo/bar/ internally to /foo/bar.php.

和给力的结尾的斜线,试试这条规则:

And to force the trailing slash, try this rule:

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule .*[^/]$ $0/ [L,R=301]

这篇关于htaccess的code,除去延伸和补充+力斜线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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