如何使用htaccess的重写规则重定向特定的URL [英] How redirect specific url using htaccess rewrite rules

查看:191
本文介绍了如何使用htaccess的重写规则重定向特定的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要如何把这个网址:

http://domain.com/index.html#!

要这样:

http://domain.com/

使用htaccess的重写规则?

Using htaccess rewrite rules?

推荐答案

有关 /index.html / 你需要:

RewriteEngine On
RewriteCond %{THE_REQUEST} \ /+index\.html
RewriteRule ^ / [R=301,L]

您的网址

这可以顺带解决了#!部分为好,但URL的一部分被称为片段,然后是通过东西是在客户机侧添加那里,它停留在客户端,它是从未的发送给服务器。因此,没有htaccess的或服务器端的任何东西会知道它甚至存在。如果你想删除它,你需要弄清楚什么脚本添加它,并删除脚本。如果你简单地添加javacsript删除它,其他的脚本可能会在无意中将其重新添加。

That could incidentally fix the #! part of your URL as well, but that part of the URL is called a fragment, and is added there by something that's on the client side, it stays on the client side, and it is never transmitted to the server. So no htaccess or server side anything is going to know it's even there. If you want to remove it, you need to figure out what script is adding it there and remove the script. If you simply add javacsript to remove it, that other script may inadvertently add it back.

if (location.href.indexOf("#") > -1) {
    location.assign(location.href.replace(/\/?#/, "/"));
}

这篇关于如何使用htaccess的重写规则重定向特定的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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