Support » Plugin: Permalink Manager Lite » How to set amp url’s?

  • Resolved diEfoRyoU

    (@dieforyou)


    Hi i want to add category url’s end .html your plugin ok working and doing 301 its okey. But what about amp url’s?

    for example: website.com/toruism-firms.html my category name. and amp url: website.com/tourism-firms/amp when i try enter this url its going website.com/tourism-firms.html i need : website.com/tourism-firms.html/amp

    because i have indexed google about 10.000 amp url’s.

Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Author Maciej Bis

    (@mbis)

    Hi @dieforyou,

    could you add this code to functions.php file in your (child) theme directory?

    function pm_fix_amp_pages($request) {
    	global $wp;
    
    	if(!empty($wp->request) && strpos($wp->request, '/amp') !== false) {
    		$request['do_not_redirect'] = 1;
    	}
    
    	return $request;
    }
    add_filter('request', 'pm_fix_amp_pages', 999);

    This would stop the canonical redirect if AMP page is requested.

    Best regards,
    Maciej

    Hi thank you. Now amp url’s working.i will check again. another question. if i buy 45 dolar for one site. can i use subdomains website too?

    And i have maybe 1100 categories. can i make category url’s end all categories .html at once or i should do one by one.

    • This reply was modified 3 weeks, 4 days ago by diEfoRyoU.
    Plugin Author Maciej Bis

    (@mbis)

    Yes, you can use the single license on subdomains.

    As regards categories, you can add .html to the end of permastructure settings for categories and regenerate the categories permalinks using bulk tools:
    https://permalinkmanager.pro/docs/how-to-append-html-extension-to-wordpress-permalinks/
    https://permalinkmanager.pro/docs/basics/how-to-regenerate-the-custom-permalinks/

    Best regards,
    Maciej

    Thank you for answer!

    can i do:

    for example: my old url: website.com/torusim-country
    new url: website.com/torusim-country.html

    when try go: website.com/torusim-country/amp
    its redirection and open like this: website.com/torusim-country.html/amp

    is it possible?

    Plugin Author Maciej Bis

    (@mbis)

    Could you send me some live example?

    Hi, its a post URL cause i didnt buy pro yet. İf we can do for amp what i want then I can buy pro and I will use this plugin only for category.

    https://testyazili.com/4-sinif-din-kulturu-1-donem-1-yazili/164.html
    If I go: https://testyazili.com/4-sinif-din-kulturu-1-donem-1-yazili/164/amp I want redirection https://testyazili.com/4-sinif-din-kulturu-1-donem-1-yazili/164.html/amp then google will change amp url’s with new permalinks.

    Plugin Author Maciej Bis

    (@mbis)

    Hi @dieforyou,

    could you try to add one more snippet?

    function pm_canonical_redirect_amp() {
    	global $wp_query, $wp;
    
    	// Stop redirect loop
    	if(!empty($wp_query->query_vars['do_not_redirect'])) { return; }
    
    	// Triger only for selected post types or taxonomies
    	// if(!is_singular(array('post', 'page')) && !is_category() && !is_tax(array('custom-taxonomy', 'another-custom-taxonomy'))) { return; }
    
    	if(preg_match('/^((?!.html).)*\/amp$/', $wp->request)) {
    		$correct_url = sprintf('%s/%s', trim(get_home_url(), "/"), str_replace('/amp', '.html/amp', $wp->request));
    
    		wp_safe_redirect($correct_url, 301);
    		exit();
    	}
    }
    add_action('template_redirect', 'pm_canonical_redirect_amp', 0);
    pm_canonical_redirect_amp');

    Due to increasing number of requests for custom solutions, I am no longer able to provide them for free version users. Actually, I help users with bugs and answer on their general questions here. If this does not work, you will need to customize the code.

    Best regards,
    Maciej

    • This reply was modified 3 weeks, 3 days ago by Maciej Bis.

    hi @mbis bis some error this code i think:

    pm_canonical_redirect_amp’);

    syntax error, unexpected ”);’ (T_ENCAPSED_AND_WHITESPACE)

    • This reply was modified 3 weeks, 3 days ago by diEfoRyoU.

    i want to buy pro i will use it for category because. if i can do what i need then i can buy.

    Plugin Author Maciej Bis

    (@mbis)

    Hi @dieforyou

    please copy it without the last line of code:

    function pm_canonical_redirect_amp() {
    	global $wp_query, $wp;
    
    	// Stop redirect loop
    	if(!empty($wp_query->query_vars['do_not_redirect'])) { return; }
    
    	// Triger only for selected post types or taxonomies
    	// if(!is_singular(array('post', 'page')) && !is_category() && !is_tax(array('custom-taxonomy', 'another-custom-taxonomy'))) { return; }
    
    	if(preg_match('/^((?!.html).)*\/amp$/', $wp->request)) {
    		$correct_url = sprintf('%s/%s', trim(get_home_url(), "/"), str_replace('/amp', '.html/amp', $wp->request));
    
    		wp_safe_redirect($correct_url, 301);
    		exit();
    	}
    }
    add_action('template_redirect', 'pm_canonical_redirect_amp', 0);

    hi @mbis i deleted your first code.
    function pm_fix_amp_pages($request) {
    global $wp;

    if(!empty($wp->request) && strpos($wp->request, ‘/amp’) !== false) {
    $request[‘do_not_redirect’] = 1;
    }

    return $request;
    }
    add_filter(‘request’, ‘pm_fix_amp_pages’, 999);

    with your last code now working how i want. its okey? i only using last code.

    only this code:

    function pm_canonical_redirect_amp() {
    	global $wp_query, $wp;
    
    	// Stop redirect loop
    	if(!empty($wp_query->query_vars['do_not_redirect'])) { return; }
    
    	// Triger only for selected post types or taxonomies
    	// if(!is_singular(array('post', 'page')) && !is_category() && !is_tax(array('custom-taxonomy', 'another-custom-taxonomy'))) { return; }
    
    	if(preg_match('/^((?!.html).)*\/amp$/', $wp->request)) {
    		$correct_url = sprintf('%s/%s', trim(get_home_url(), "/"), str_replace('/amp', '.html/amp', $wp->request));
    
    		wp_safe_redirect($correct_url, 301);
    		exit();
    	}
    }
    add_action('template_redirect', 'pm_canonical_redirect_amp', 0);

    working well. is it work for category too?

    • This reply was modified 3 weeks, 3 days ago by diEfoRyoU.
    • This reply was modified 3 weeks, 3 days ago by diEfoRyoU.
    Plugin Author Maciej Bis

    (@mbis)

    Please use this code instead:

    function pm_canonical_redirect_amp() {
    	global $wp_query, $wp;
    
    	// Stop redirect loop
    	if(!empty($wp_query->query_vars['do_not_redirect'])) { return; }
    
    	// Triger only for selected post types or taxonomies
    	// if(!is_singular(array('post', 'page')) && !is_category() && !is_tax(array('custom-taxonomy', 'another-custom-taxonomy'))) { return; }
    
    	if(preg_match('/^((?!.html).)*\/amp$/', $wp->request)) {
    		$correct_url = sprintf('%s/%s', trim(get_home_url(), "/"), str_replace('/amp', '.html/amp', $wp->request));
    
    		wp_safe_redirect($correct_url, 301);
    		exit();
    	}
    }
    add_action('template_redirect', 'pm_canonical_redirect_amp', 0);
    
    function pm_fix_amp_pages($request) {
    	global $wp;
    
    	if(!empty($wp->request) && strpos($wp->request, '/amp') !== false && strpos($wp->request, '.html') !== false) {
    		$request['do_not_redirect'] = 1;
    	}
    
    	return $request;
    }
    add_filter('request', 'pm_fix_amp_pages', 999);

    hi i bought pro plugin. you are so fast help. i think you can solve if i have problems 🙂 thank you! i download allready pro. i will do now. if i have problem i write you. from here? or another place?

    and dear @mbis i will use only pro plugin or pro plugin work with free plugin?

    • This reply was modified 3 weeks, 3 days ago by diEfoRyoU.
    Plugin Author Maciej Bis

    (@mbis)

    If you have any questions related to Permalink Manager Pro please use my email directly: contact /at/ maciejbis.net

Viewing 15 replies - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.