简体   繁体   中英

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

to

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

for seo i have auto delete all extra character after .htm or .php or specefic character like ==

in htaccess

You can see if the URL has a fragment and, if it does, then remove it:

$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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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