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 重定向到index.php并删除尾部的slash.htaccess_Apache_.htaccess_Mod Rewrite_Server_Webserver - Fatal编程技术网

Apache 重定向到index.php并删除尾部的slash.htaccess

Apache 重定向到index.php并删除尾部的slash.htaccess,apache,.htaccess,mod-rewrite,server,webserver,Apache,.htaccess,Mod Rewrite,Server,Webserver,这里似乎有很多这样的问题,但找不到符合我当前代码的答案: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ public/index.php [QSA,L] 这会将所有内容重定向到public/index.php,这很好,但我想去掉尾随斜杠,以便example.com/foo/变成example.com/foo您可以在当前规则之前插入尾随斜杠删除代码: Rewr

这里似乎有很多这样的问题,但找不到符合我当前代码的答案:

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^ public/index.php [QSA,L]

这会将所有内容重定向到
public/index.php
,这很好,但我想去掉尾随斜杠,以便
example.com/foo/
变成
example.com/foo

您可以在当前规则之前插入尾随斜杠删除代码

RewriteEngine On

## Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.+)/+$
RewriteRule ^ %1 [R=301,NE,L]

## forward all requests to public/index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ public/index.php [L]

上述代码将
foo/
重定向到
public/foo/
。我需要在浏览器URL中“隐藏”
public
。很抱歉,我使用的是很久以前的样板文件是相同的:(它在localhostLet中)。