我有一个名为friends.html.的文件
然后我有一个朋友文件夹
我的htaccess运行良好,localhost/friends/按照我的意愿打开我的friends.html
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.html
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !('.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
现在,如果我的friends/best/文件夹中有mary.html,我如何让localhost/friends/best/mary/转到localhost/frients/best/mary.html?
这不适用于当前文件-非常感谢
如果您的问题只是一个两个深度的目录,那么您可以添加以下行:
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$ /$1/$2/$3.html
正如我在你的例子中看到的,你可能需要的唯一规则是:
RewriteRule ^(.*)/$ /$1.html
哪个执行以下操作:
/friends -> /friends.html
/friends/john/ -> /friends/john.html
/friends/best/mary/ -> /friends/best/mary.html
/friends/of/my/friends/george/ -> /friends/of/my/friends/george.html