htaccess在根目录上删除落后斜线,重定向太多次 我使用我的index.php文件来处理我域的所有请求(当然,除了CSS,JS等,以及实际存在的文件)。它可以很好地工作。我现在想要的是删除所有拖尾s ...

问题描述 投票:0回答:0
here:

htaccess:添加/删除url

中的斜线 我认为它是一个非常优雅的解决方案,实际上是有效的,但这是我发现很奇怪的:

在实时域,它的工作正常 在localhost,localhost/mydomain.com/folder/file/file/retirects fine,localhost/mydomain.com/folder/to localhost/mydomain.com/简单地说“ Localhost重定向您很多次”。 如何使重定向在实时服务器和Localhost上正常工作?还是我应该忘记这一点,仅在实时服务器上使用HTACCESS?

这里是我的htaccess文件的其余部分。粘贴所有命令之一只是影响或覆盖另一个命令,我不是HTACCESS专家。谢谢
    RewriteEngine On RewriteCond %{REQUEST_URI} /(.*)/$ RewriteRule ^ /%1 [R=301,L] #added slash here too, don't forget it RewriteCond %{SERVER_PORT} 80 RewriteCond %{HTTP_HOST} ^example\.net$ [OR] RewriteCond %{HTTP_HOST} ^www\.example\.net$ RewriteRule ^(.*)$ https://example.net/$1 [R=301,L] RewriteCond %{HTTP_HOST} www.example.net RewriteRule (.*) https://example.net/$1 [R=301,L] #RewriteRule ^(.*)index\.(php|html?)$ /$1 [R=301,NC,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?url=$1 [L,QSA] #Header set X-Frame-Options "ALLOW-FROM https://whatismyscreenresolution.net/" Redirect 301 "/brand" "/brands" ErrorDocument 404 /404.php ErrorDocument 502 /502.shtml ErrorDocument 504 /504.shtml ErrorDocument 508 /508.shtml <Files ~ "\.env$"> Order Allow,Deny Deny from All </Files> <Files .htaccess> Order allow,deny Deny from All </Files> Options -Indexes <filesMatch ".(jpg|jpeg|png|gif|ico|webp|js)$"> Header set Cache-Control "max-age=2592000, public" </filesMatch> <filesMatch ".(css|js)$"> Header set Cache-Control "max-age=60, public" </filesMatch>
  • 这是一个棘手的情况,因为您的重定向规则在实时域上很好地工作,但是在Local主机上它会创建一个重定向循环 - 这可能是由于URL在Local主机上构造的方式(例如,路径中有一个额外的目录)。 您可以尝试:
RewriteCond %{REQUEST_URI} !^/$ RewriteCond %{REQUEST_URI} /(.*)/$ RewriteRule ^ /%1 [R=301,L]


php apache .htaccess mod-rewrite
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.