如何使用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(/\/?#/, "/"));
}