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

199
Visualizações
.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 Respostas
Responde à pergunta

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 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