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

140
Visualizações
Apache 2.4 RewriteRule only working with domain name

I'm moving an old site from apache 2.2 to 2.4

I've got a vhost.conf file that contains the following rewriterule:

RewriteRule ^/news/[0-9]{4}/[A-za-z]{3}/([0-9a-zA-Z-]*)/([0-9]{4})([0-9]{6})/?$ "/news/article.cfm?article_id=$3&urltitle=$1&clk=$2" [NE,L]

So I'm trying to turn this url: https://example.com/news/2016/Feb/Article-Title/0025012345

into this: https://example.com/news/article.cfm?article_id=012345&urltitle=Article-Title&clk=0025

Depending on what I put in the 2nd part of the RewriteRule I get the following:

"https://example.com/news/article.cfm?article_id=$3&urltitle=$1&clk=$2" this works fine but I don't want to specify the hostname as it gets used on dev/staging/live servers, so the URLs change

"/news/article.cfm?article_id=$3&urltitle=$1&clk=$2" this throws a 404 which shows up in the access_log

"news/article.cfm?article_id=$3&urltitle=$1&clk=$2" this throws a 503 which shows up in the access_log

So I know I'm correctly identifying the URL in the first part of the rule and grabbing the correct components with my regex, as specifying the full domain name shows the correct URL manipulation.

I'm completely failing to do a relative redirect though, and I'm certain this rule works in Apache 2.2

I'm using the following software:

CentOS Linux release 7.7.1908 (Core)

Server version: Apache/2.4.6 (CentOS) Server built: Aug 8 2019 11:41:18

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

0

Obviosuly, the answer is in the manual... which I should have read in more detail:

https://httpd.apache.org/docs/2.4/rewrite/remapping.html#old-to-new

Assume we have recently renamed the page foo.html to bar.html and now want to provide the old URL for backward compatibility. However, we want that users of the old URL even not recognize that the pages was renamed - that is, we don't want the address to change in their browser.

RewriteEngine  on
RewriteRule    "^/foo\.html$"  "/bar.html" [PT]

The key thing here being the [PT], that fixed it for me:

RewriteRule ^/news/[0-9]{4}/[A-za-z]{3}/([0-9a-zA-Z-]*)/([0-9]{4})([0-9]{6})/?$ "/news/article.cfm?article_id=$3&urltitle=$1&clk=$2" [PT,NE,L]
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