我有以下urlwww.example.com/advice/现在注意在URL的末尾的斜线? 我希望将其移除为www.example.com/advice 。 现在,当我在浏览器中input该URL时,我将redirect到带有斜线的尾部,即使以curl为例。 现在我知道后面的斜杠正在增加,因为通知是一个实际的目录。
[steve@dev dev.www.example.com]$ curl -I https://dev.www.example.com/advice -k HTTP/1.1 301 Moved Permanently Date: Fri, 25 Nov 2016 08:20:11 GMT Server: Apache/2.4.6 (CentOS) Location: https://dev.www.example.com/advice/ Cache-Control: max-age=0 Expires: Fri, 25 Nov 2016 08:20:11 GMT Connection: close Content-Type: text/html; charset=iso-8859-1
[steve@dev dev.www.example.com]$ curl -I https://dev.www.example.com/advice/ -k HTTP/1.1 200 OK Date: Fri, 25 Nov 2016 08:21:19 GMT Server: Apache/2.4.6 (CentOS) X-Powered-By: PHP/5.6.27 Set-Cookie: flarum_session=mfbou2hcbvcobhncnaqlvl9bm7; Path=/; HttpOnly X-CSRF-Token: WV69M1oi8POqOcXi6MvwKhbJQ72Tmo2WpFn3oxwq Content-Length: 10339 Cache-Control: max-age=0 Expires: Fri, 25 Nov 2016 08:21:19 GMT Vary: Accept-Encoding Access-Control-Allow-Origin: *.example.com Connection: close Content-Type: text/html; charset=UTF-8
在.htacess里面我试过了:
DirectorySlash Off
这导致了403没有斜线
[steve@dev dev.www.example.com]$ curl -I https://dev.www.example.com/advice -k HTTP/1.1 403 Forbidden Date: Fri, 25 Nov 2016 08:53:15 GMT Server: Apache/2.4.6 (CentOS) Connection: close Content-Type: text/html; charset=iso-8859-1
我还添加了以下重写规则,但没有任何更改
RewriteRule ^.*(advice)\/$ $1 [L,R=301]
现在, advice是我安装了一个论坛平台,在同一个目录中,我安装了一个CMS,如下所示
├── advice │ ├── admin.php │ ├── api.php │ ├── assets │ ├── composer.json │ ├── composer.lock │ ├── config.php │ ├── CONTRIBUTING.md │ ├── index.php <-- Forum entry point │ ├── LICENSE │ ├── Procfile │ ├── readme.md │ ├── scripts │ ├── storage │ ├── Vagrantfile │ └── vendor ├── assets ├── cms ├── codeception.yml ├── commands ├── composer.json ├── composer.lock ├── crontask ├── dropzone ├── email-helpers ├── favicon.ico ├── framework ├── gridfield-bulk-editing-tools ├── gridfieldextensions ├── index.php <-- CMS Entry point ├── kickassets ├── liveseo ├── minify ├── README.md ├── reports ├── setup.php ├── shortcodable ├── silverstripe-cache ├── siteconfig ├── _ss_environment.php ├── tests ├── themes ├── trait-loader ├── vendor └── web.config
Apache版本Apache/2.4.6 (CentOS)
你可以在这里findbuild议.htaccess 在这里findcms的build议
如果它有助于CMS是银 条纹和论坛是flamma
如果你删除一个目录的斜线,并仍然期望目录索引文件(在该目录中)被返回,那么你需要手动“修复”URL内部重写到索引文件。 (你基本上需要通过closuresDirectorySlash Off来重做你已经完成的操作。)
在根.htaccess文件中的其他mod_rewrite指令之前,请尝试如下所示:
DirectorySlash Off RewriteEngine On RewriteCond %{REQUEST_FILENAME} -d RewriteCond %{REQUEST_URI} !/$ RewriteCond %{REQUEST_FILENAME}/index.php -f RewriteRule (.*) $1/index.php [L]
对于物理目录的所有请求,不会以index.php存在于该目录中的斜线结尾,然后在内部重写为index.php 。
或者,你可以追加斜线(通过内部重写),然后允许mod_dir向DirectoryIndex发出一个子请求。 例如:
RewriteRule (.*) $1/ [L]
假设你有一个DirectoryIndex集合(如果这个工作先前可能有的话),那么mod_dir将在/advice/到/advice/index.php内部重写请求(严格来说是一个子请求)。 然而,现在这是一个两阶段的过程,所以你可以用mod_rewrite来完成这一切(除非你有不同的目录索引文件)。
以上是所有目录的一般情况。 你可以更具体地检查一下目录/ URL:
RewriteRule ^advice$ advice/index.php [L]
如果请求是/advice然后在内部重写到/advice/index.php – 这不检查是否是一个目录,这只是假设。