Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

645
Visualizações
How to check if a given URL string ends with "/index.*" or simply "/" and remove it, in PHP?

I'm trying to check for /index.[ php | htm | html | asp ], etc. (basically any wildcard suffix)

or simply "/"

to convert a canonical URL such as http://www.example.com/index.php or http://www.example.com/ to just http://www.example.com so I can just use one consistent PHP variable in my canonicalmeta tag throughout all the pages on my site.

I dont want the script to effect URLs that are NOT homepages such as http://www.example.com/page.php

REGEX preferred, but not necessary.

I'm working from the variable $current_Webpage_Complete_URL_Address in "domain_info.php" from this script: http://www.perfecterrordocs.com

I want to use just one PHP variable, formed from modifying $current_Webpage_Complete_URL_Address, if that makes any sense.

Please ask for further clarification, if neccassary.

Edit: Also, I want the newly formed variable to be named $current_Webpage_Canonical_URL_Address

Edit(2): I just ran into another problem. Even when I do find a match with preg_match how do I remove that particular ending sub-string?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Final Answer (Works Perfectly!!):

$current_Webpage_Canonical_URL_Address = preg_replace('/((\\index)\.[a-z]+)$/', '', $current_Webpage_Complete_URL_Address);

$current_Webpage_Canonical_URL_Address = preg_replace('/\/$/', '', $current_Webpage_Canonical_URL_Address);
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda