简体   繁体   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

I've tried some different solutions I've found on the web on my .htaccess file (placed in the root of my website), but I always end up with an "Internal Server Error"... 我尝试了一些在Web上的.htaccess文件(位于网站根目录中)上找到的其他解决方案,但最终总是遇到“内部服务器错误” ...

I need a generic rule to remove a specific folder from the URL and the extension of all the files contained in it (adding a trailing slash at the end), with a redirection to the rewrited url. 我需要一条通用规则,以从URL及其包含的所有文件的扩展名中删除特定文件夹(在末尾添加斜杠),并重定向到重写的url。 So, for example: 因此,例如:

the folder I want to work on is called "pages", so the rule should not affect any other folder, and I want that the url 我要处理的文件夹称为“页面”,因此该规则不应影响任何其他文件夹,并且我希望该网址

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

and

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

and

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

and so on... 等等...

How can I achieve that? 我该如何实现?

This would be more logical in 2 rules: 在以下两个规则中,这更合乎逻辑:

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

Didn't test the rules but this should get you there. 没有测试规则,但这应该可以帮助您。

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

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