Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

644
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda