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

168
Visualizações
mod_rewrite Clean URL rewriting

I'm trying to write clean url's for my website. I'm a rookie at this so forgive me. My .htaccess file currently looks like this:

RewriteEngine On
RewriteRule ^([a-zA-Z0-9-]+)$ something.php?query=$1
RewriteRule ^([a-zA-Z0-9-]+)/$ something.php?query=$1

The first rule seems to work. For example website.com/good-looking-query-string does in fact rewrite to website.com/something.php?query=ugly+looking+query+string

The second rule is where I'm having a problem. I can't get that trailing slash to work. For example website.com/good-looking-query-string/ appears to pull up the page but without any CSS rules applied. I noticed all the links end up appended to the query string also. For example the link back to index.php ends up like website.com/good-looking-query-string/index.php

I need to get that trailing slash to work. What in the world am I doing wrong?

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

0

You can combine two line in one line:

RewriteEngine On
RewriteRule ^([a-zA-Z0-9-]+)/?$ something.php?query=$1

In this case / will be optional

over 4 years ago · Santiago Trujillo Relatório

0

Your issue is client side, you are using relative paths but you need to be using Root-relative paths. A URL of:

website.com/good-looking-query-string

loads from the root. A url of:

website.com/good-looking-query-string/

loads from the good-looking-query-string directory.

So instead of href="style.css" you should have "href="/style.css"and the index issue should behref="/index.php"instead ofhref="index.php"`.

As noted in the earlier comment your regex could be simplified by adding a ? on the trailing slash to make it option. That is not your issue though, just simplifies the rules.

RewriteRule ^([a-zA-Z0-9-]+)/?$ something.php?query=$1
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