Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache mod_一起删除斜杠和.html的重写规则_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Apache mod_一起删除斜杠和.html的重写规则

Apache mod_一起删除斜杠和.html的重写规则,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,我尝试了多种组合,但无法在Apache中使用mod_rewrite设置以下场景: domain.com/folder/-删除尾部“/”-结果=domain.com/folder domain.com/folder/filename.html-删除.html并不要添加尾随“/”—Result=domain.com/folder/filename(这适用于任何未索引的文件名) domain.com/folder/index.html-删除文件名、扩展名和尾随“/”—结果=domain.com/fol

我尝试了多种组合,但无法在Apache中使用mod_rewrite设置以下场景:

domain.com/folder/-删除尾部“/”-结果=domain.com/folder

domain.com/folder/filename.html-删除.html并不要添加尾随“/”—Result=domain.com/folder/filename(这适用于任何未索引的文件名)

domain.com/folder/index.html-删除文件名、扩展名和尾随“/”—结果=domain.com/folder

[编辑]-我目前拥有的内容,它删除了.html,但添加了斜杠。但现在我需要删除URL中的所有斜杠(包括文件夹和文件):


如果有任何帮助,我们将不胜感激。

您目前的代码有哪些内容?现在我有以下内容删除.html并添加斜杠,但我现在需要从所有URL(包括文件夹和.html文件,但扩展名未显示)中删除斜杠:#添加尾部斜杠重写cond%{REQUEST_FILENAME}-f RewriteCond%{REQUEST_URI}!(\.[a-zA-Z0-9]{1,5}|/|#(.*)$RewriteRule^(.*)$$1/[R=301,L]#从url RewriteCond%{REQUEST_FILENAME}中删除.html扩展名-d RewriteCond%{REQUEST\u FILENAME}\.html-f RewriteRule^([^\.]+)/$$1.html RewriteCond%{THE_REQUEST}^[A-Z]{3,9}\/.\.html\HTTP/RewriteRule^(.*)\.html$/$1[R=301,L]在这个问题上再加上一句,它在评论中是不可理解的。至少可以说,这是漫长的一天;)#尴尬已编辑。您想删除斜杠,但有添加斜杠的规则。为什么?
  Options +FollowSymLinks
  RewriteEngine On
  RewriteBase /
# Add trailing slash to url
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
  RewriteRule ^(.*)$ $1/ [R=301,L]
# Remove .html extension from url
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME}\.html -f
  RewriteRule ^([^\.]+)/$ $1.html

  RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
  RewriteRule ^(.*)\.html$ /$1 [R=301,L]