Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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 301如果页面有尾随斜杠,则重定向_.htaccess - Fatal编程技术网

.htaccess 301如果页面有尾随斜杠,则重定向

.htaccess 301如果页面有尾随斜杠,则重定向,.htaccess,.htaccess,假设我的域名页面是 www.website.com/about 然后用户将 www.website.com/about/(尾随斜杠)结尾处 它返回同一页,太好了。然而,搜索引擎可能会将其视为重复内容,因为它可以被视为2页 如果用户在一个页面的末尾放了一个尾随斜杠,我希望他们执行301重定向到正确的页面 我的.htaccess文件如下所示 # Begin cache control # ExpiresActive on ExpiresDefault "now plus 14

假设我的域名页面是 www.website.com/about 然后用户将 www.website.com/about/(尾随斜杠)结尾处

它返回同一页,太好了。然而,搜索引擎可能会将其视为重复内容,因为它可以被视为2页

如果用户在一个页面的末尾放了一个尾随斜杠,我希望他们执行301重定向到正确的页面

我的.htaccess文件如下所示

    # Begin cache control #
    ExpiresActive on
    ExpiresDefault "now plus 1440 minutes"
    ExpiresByType text/html "now plus 1440 minutes"
    <FilesMatch "\.(css|png|bmp|ico|htm|gff|html|js|jpg|jpeg|gif|gcf)$">
    FileETag MTime Size
    ExpiresDefault "now plus 1440 minutes"
    </FilesMatch>


    # End cache control #
    Options +FollowSymLinks -MultiViews


    AddOutputFilterByType DEFLATE text/html image/png image/jpeg image/jpg text/css text/javascript 
    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /
    ## hide .php extension
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
    RewriteRule ^ %1 [R,L,NC]
    RewriteCond %{DOCUMENT_ROOT}/$1.php -f
    RewriteRule ^(.*?)/?$ $1.php [L,NC]
#开始缓存控制#
过期于
ExpiresDefault“现在加1440分钟”
ExpiresByType text/html“现在加1440分钟”
FileTag MTime大小
ExpiresDefault“现在加1440分钟”
#端缓存控制#
选项+以下符号链接-多视图
AddOutputFilterByType DEFLATE text/html image/png image/jpeg image/jpg text/css text/javascript
#打开mod_rewrite
重新启动发动机
重写基/
##php扩展名
重写cond%{THE_REQUEST}^[A-Z]{3,}\s([^.]+)\.php[NC]
重写规则^1[R,L,NC]
重写cond%{DOCUMENT_ROOT}/$1.php-f
重写规则^(.*)/?$$1.php[L,NC]

有人知道我是如何做到这一点的吗?因为我尝试的一切都不起作用。

您可以在上一条删除尾随斜杠的规则之前插入此规则:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^(.+?)/$ /$1 [R=302,NE,L]