Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3759318
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:17:53+00:00 2026-05-19T10:17:53+00:00

for building a clean canonical url, that always returns 1 base URL, im stuck

  • 0

for building a clean canonical url, that always returns 1 base URL, im stuck in following case:

<?php
# every page
$extensions = $_SERVER['REQUEST_URI'];  # path like: /en/home.ast?ln=ja
$qsIndex = strpos($extensions, '?');    # removes the ?ln=de part
$pageclean = $qsIndex !== FALSE ? substr($extensions, 0, $qsIndex) : $extensions;
$canonical = "http://website.com" . $pageclean;   # basic canonical url
?>

<html><head><link rel="canonical" href="<?=$canonical?>"></head>

when URL : http://website.com/de/home.ext?ln=de
canonical: http://website.com/de/home.ext

BUT I want to remove the file extension aswell, whether its .php, .ext .inc or whatever two or three char extension .[xx] or .[xxx] so the base url becomes: http://website.com/en/home

Aaah much nicer! but How do i achieve that in current code?
Any hints are much appreciated +!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T10:17:54+00:00Added an answer on May 19, 2026 at 10:17 am

    Think this should do it, just strip off the end if there is an extension, just like you did for the query string:

    $pageclean = $qsIndex !== FALSE ? substr($extensions, 0, $qsIndex) : $extensions;
    $dotIndex = strrpos($pageclean, '.');
    $pagecleanNoExt = $dotIndex !== FALSE ? substr($pageclean, 0, $dotIndex) : $pageclean; 
    $canonical = "http://website.com" . $pagecleanNoExt;   # basic canonical url
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

building a site using PHP and MySQL that needs to store a lot of
I'm building a pseudo-variable parser in PHP to allow clean and simple syntax in
I'm building a web app that processes the text in a web page, adds
Building a website that has English & Japanese speaking users, with the Japanese users
I am currently building a Website that uses a blackletter font. I try to
Background: I am building a webapp that makes use of JQuery and the Facebook
I'm building an Outlook 2010 add-in that will tie into our ticketing system using
I'm building a Rails app that needs to connect to a custom TCP data
Building on this this post , I needed a clean way to extract nodes
I'm building my first Flask app and I can't figure out a good, clean

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.