Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.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
Php 从.htaccess配置中删除结尾斜杠_Php_.htaccess - Fatal编程技术网

Php 从.htaccess配置中删除结尾斜杠

Php 从.htaccess配置中删除结尾斜杠,php,.htaccess,Php,.htaccess,我创建了一个名为test.example.com的目录,它在目录test.example.com 我在域上有以下路径: http://example.com/test.example.com/ 和.htaccess,配置如下 # php -- BEGIN cPanel-generated handler, do not edit # Set the “ea-php56” package as the default “PHP” programming language. Options

我创建了一个名为
test.example.com
的目录,它在目录
test.example.com

我在域上有以下路径:

http://example.com/test.example.com/

和.htaccess,配置如下



# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php56” package as the default “PHP” programming language.


Options +FollowSymLinks
RewriteEngine On
RewriteBase /


RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [R=301,L]

<IfModule mime_module>
  AddHandler application/x-httpd-ea-php56 .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit


#php——开始cPanel生成的处理程序,不编辑
#将“ea-php56”包设置为默认的“PHP”编程语言。
选项+FollowSymLinks
重新启动发动机
重写基/
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)/$/$1[R=301,L]
AddHandler应用程序/x-httpd-ea-php56.php.php5.phtml
#php——结束cPanel生成的处理程序,不编辑

访问
http://example.com/test.example.com/
我想在删除的尾随斜杠上重定向
http://example.com/test.example.com
使用index.html托管

嗯,您需要一个外部重定向来删除可能的尾部斜杠:

RewriteRule ^/?(test\.example\.com)/$ /$1 [R=301]
如果您还希望将该规则应用于该文件夹下的路径,则可以执行以下操作:

RewriteRule ^/?(test\.example\.com)(.*)/$ /$1$2 [R=301]
一开始使用302临时重定向是一个好主意,在确定所有设置都正确后,只需将其更改为301永久重定向。这样可以防止在尝试时出现缓存问题

此实现将在http服务器主机配置中或在动态配置文件(“.htaccess”文件)中同样工作。显然,重写模块需要在http服务器中加载,并在http主机中启用。在使用动态配置文件的情况下,您需要注意在主机配置中启用该文件的解释,并且该文件位于主机的
DOCUMENT\u ROOT
文件夹中


还有一个一般性的注释:您应该总是更喜欢将这些规则放在http服务器主机配置中,而不是使用动态配置文件(“.htaccess”)。这些动态配置文件增加了复杂性,通常是导致意外行为的原因,难以调试,而且它们确实降低了http服务器的速度。只有在您无法访问真正的http服务器主机配置(读:真正廉价的服务提供商)或坚持编写自己的规则的应用程序(这显然是一个安全噩梦)的情况下,才提供它们作为最后一个选项

test.example.com
是一个真正的目录,出于安全原因,删除目录后面的斜杠不是一个好主意。