How redirect specific url using htaccess rewrite r

2019-09-07 03:38发布

How can I redirect this URL:

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

To this One:

http://domain.com/

Using htaccess rewrite rules?

标签: .htaccess
1条回答
闹够了就滚
2楼-- · 2019-09-07 04:01

For /index.html to / you need:

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

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(/\/?#/, "/"));
}
查看更多
登录 后发表回答