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中)。