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

176
Vistas
Replace substring in URL via RewriteEngine

im desperately trying to make RewriteEngine to rewrite the following pattern:

https://example.com/api/model/id/
https://example.com/staging/api/model/id/

internally to

https://example.com/index.php/model/id/
https://example.com/staging/index.php/model/id/

I already tried several suggestions from several boards but none of them worked out for me. Ideally the rule should just search for "/api/" and replace it with "/index.php/". I can't figure out, why it is so hard to make that work, my other rules worked out fine till now...

Here is my last try:

RewriteEngine On
RewriteRule ^(.+)/api/(.+)$ $1/index.php/$2 [R=301,L]
# RewriteRule ^/api/(.*)$ /index.php/$1 [R=301,L,NC]
# RewriteRule ^(.+)/api/(.+)$ http://localhost/dev/someFolder/index.php/$2 [R=301,L]

What am I making wrong? I'm just telling the rule to make ($1)/api/($2) to ($1)/index.php/($2), that shouldn't be that hard. Ideally the rule also shouldn't care about whats standing before the "/api/" pattern.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

something like this...

RewriteEngine On
                
RewriteRule ^api/(.*)$ /index.php/$1 [NC]

RewriteRule ^staging/api/(.*)$ /staging/index.php/$1 [NC]
over 4 years ago · Santiago Trujillo Denunciar

0

I found a work-around, which seems to work out fine in most use-cases:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) ./index.php/$1 [L]

Found the answer here: htaccess remove index.php from url

Just keep in mind, that you have to put your files in a subdir named after the string you want to replace "index.php" with (e.g. to replace /index.php/$1 with /api/$1 you have to put all your files into a subdir named api).

This is just perfectly fine for my use-case.

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