Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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
.htaccess 在我的URL末尾添加正斜杠会破坏它们_.htaccess_Url_Mod Rewrite_Url Rewriting - Fatal编程技术网

.htaccess 在我的URL末尾添加正斜杠会破坏它们

.htaccess 在我的URL末尾添加正斜杠会破坏它们,.htaccess,url,mod-rewrite,url-rewriting,.htaccess,Url,Mod Rewrite,Url Rewriting,我想在我所有URL的末尾加一个正斜杠 目前,我网站上的一个示例链接是: 当我将此更改为: 以下是我的访问权限: AddType application/x-httpd-php .html AddType application/x-httpd-php .htm RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.html -f RewriteRule ^(.*)$ $1.h

我想在我所有URL的末尾加一个正斜杠

目前,我网站上的一个示例链接是:

当我将此更改为:

以下是我的访问权限:

AddType application/x-httpd-php .html 
AddType application/x-httpd-php .htm

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html  [L]

为什么尾随的正斜杠会破坏URL?

规则正在破坏,因为(例如)您得到了类似于:terms of use/.html的内容 请尝试以下方法:

AddType application/x-httpd-php .html 
AddType application/x-httpd-php .htm

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/?$ $1.html  [L]

这将从请求中删除最后一个斜杠,然后将其重写到相应的文件。

感谢您的回复。现在,当我转到:(没有尾随斜杠)时,我得到一个“未找到”错误。如何使用户可以输入任意一个URL,但始终指向尾随斜杠的URL?