繁体   English   中英

Apache mod_rewrite:从url中仅删除特定文件夹,并从该文件夹内的所有文件中删除扩展名

[英]Apache mod_rewrite: remove only a specific folder from the url and remove the extension from all the files inside that folder

我尝试了一些在Web上的.htaccess文件(位于网站根目录中)上找到的其他解决方案,但最终总是遇到“内部服务器错误” ...

我需要一条通用规则,以从URL及其包含的所有文件的扩展名中删除特定文件夹(在末尾添加斜杠),并重定向到重写的url。 因此,例如:

我要处理的文件夹称为“页面”,因此该规则不应影响任何其他文件夹,并且我希望该网址

http://www.example.com/subfolder/pages/
will be rewrited/redirected to
http://www.example.com/subfolder/

http://www.example.com/subfolder/pages/page1.php
will be rewrited/redirected to
http://www.example.com/subfolder/page1/

http://www.example.com/subfolder/pages/subpages/page1.php
will be rewrited/redirected to
http://www.example.com/subfolder/subpages/page1/

等等...

我该如何实现?

在以下两个规则中,这更合乎逻辑:

  1. 删除扩展名:/subfolder/pages/(.*).[^.]+-> / subfolder / pages / $ 1 /
  2. 从URL删除页面:/subfolder/pages/(.*)-> / subfolder / $ 1

没有测试规则,但这应该可以帮助您。

暂无
暂无

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

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