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

197
Vistas
.htaccess - string in url without subfolder

The URL is the following http://local.example.com/features.html and what I need is to add a text like "country" http://local.example.com/us/feature.html but with the code I have when I click on the URL the site shows a 404 error

This is only visual without creating a US sub-folder.

The code...

RewriteEngine On
RewriteCond %{HTTP_HOST} local.example.com$ [NC]
RewriteCond %{HTTP_COOKIE} location=us [NC] --> CHECK COOKIE FOR ACTION
RewriteCond %{REQUEST_URI} !^/us/  --> EXCLUDE US FOR REDIRECT LOOP
RewriteCond %{REQUEST_URI} !^/blog/ --> EXCLUDE BLOG FOLDER WITH WORDPRESS
RewriteRule ^(.*)!\.(css|js|png|jpg)$ http://local.example.com/us/$1 [R=302,L]
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

RewriteRule ^(.*)!\.(css|js|png|jpg)$ http://local.example.com/us/$1 [R=302,L]

The RewriteRule pattern will not match the requested URL (because of the erroneous !) so this directive won't actually do anything. From this I also assume you are wanting to exclude requests for CSS, JS, .png and .jpg files? You also have a condition that excludes requests made to a /blog/ subdirectory, however, you've not mentioned this in your question?

You also reference a cookie in the code? However, you've not mentioned this in your question and this won't work in its current state (since it won't be present on initial requests), so I'll ignore this for now.

Try the following instead:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^local\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !\.(css|js|png|jpg)$
RewriteCond %{REQUEST_URI} !^/blog/
RewriteRule !^us/ /us%{REQUEST_URI} [R=302,L]

The above states, given a request for /foo/bar...

  1. For any request that does not start with /us/
  2. And is for the Host local.example.com
  3. And is not for a URL that ends with either .css, .js, .png or .jpg
  4. And does not start with /blog/
  5. Then 302 (temporary) redirect to /us/foo/bar

Unless you have multiple hosts on this account, you don't need to explicitly check the Host header as part of the rule?

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