简体   繁体   English

如何使用htaccess从网站网址末尾删除多余的字符?

[英]how to remove extra character from end of site url using htaccess?

please help me in have redirect in htaccess from http://khabarpu.com/cat/syria-news.htm#.VwHk7LGL4x4.telegram 请帮助我从http://khabarpu.com/cat/syria-news.htm#.VwHk7LGL4x4.telegram重定向htaccess

to

http://khabarpu.com/cat/syria-news.htm http://khabarpu.com/cat/syria-news.htm

for seo i have auto delete all extra character after .htm or .php or specefic character like == 对于seo我有自动删除.htm或.php之后的所有额外字符或像==的specefic字符

in htaccess 在htaccess中

You can see if the URL has a fragment and, if it does, then remove it: 您可以查看URL是否有片段,如果有,则删除它:

$url = 'http://khabarpu.com/cat/syria-news.htm#.VwHk7LGL4x4.telegram';
$fragment = parse_url($url, PHP_URL_FRAGMENT);

// Has a fragment
if ($fragment !== null) {
    // Remove it
    $url = substr_replace($url, '', strlen($url) - strlen('#'.$fragment));
}
echo $url;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM