删除后置使用的.htaccess除家用/登陆页面斜杠 [英] Remove trailing slash using .htaccess except for home / landing page

查看:216
本文介绍了删除后置使用的.htaccess除家用/登陆页面斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功地修改了我的.htaccess文件,以消除对大多数页面结尾的斜杠,但我不知道如何免除我的主页/目录?例如:

domain.com/test/成功地重定向到domain.com/test~~V

然而,当我打我的域名将追加根文件

domain.com/重定向到domain.com/index.php~~V

有没有办法,我可以添加到忽略根URL斜线,以便它不会尝试删除尾随斜线,并添加我的默认脚本的条件?这是我到目前为止有:

  RewriteEngine叙述上
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI} ^(+)/ $
重写规则^(+)/ $ / $ 1 [R = 301,L]
 

解决方案

确定。一堆的反复试验后,我回答我自己的问题。

第三行表示这必须有东西在URI以这样执行重定向如果URL只包含初始斜线不重定向。

  RewriteEngine叙述上
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{REQUEST_URI}(。*)$
重写规则^(+)/ $ http://www.domain.com/$1 [R = 301,L]
 

I've successfully modified my .htaccess file to remove trailing slashes on most pages but I'm wondering how to exempt my home page/directory? For example:

domain.com/test/ successfully redirects to domain.com/test

HOWEVER, when I hit my domain it will append the root document

domain.com/ redirects to domain.com/index.php

Is there a condition that I can add to ignore root url trailing slash so that it doesn't attempt to remove the trailing slash and add my default script? Here's what I have so far:

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

解决方案

OK. After a bunch of trial and error I answered my own question.

The third line denotes that there has to be something in the URI in order to perform the redirect thus not redirecting if the url just contains the initial slash.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} (.*)$
RewriteRule ^(.+)/$ http://www.domain.com/$1 [R=301,L]

这篇关于删除后置使用的.htaccess除家用/登陆页面斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆