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

303
Visualizações
Why is '/' the first uri evaluated by Apache Rewrite?

I'm presently working on a Windows 10/Apache2.4/PHP 7.3 dev server and accessing this url (i.e. where the root server is localhost and 'hostname' is mapped via the 'hosts' file) : hostname/page.php?m=150

I want to use apache rewrite commands to redirect any url with this pattern to hostname/homepage.php but the log file shows me my commands are not being evaluated in the way I would expect them to be evaluated.

FYI, the site is configured by a <VirtualHost> block in httpd-vhosts.conf so that's where my rewrite commands are housed.

I've stripped the virtual host block down to just this:

<VirtualHost *:80>
    DocumentRoot "C:/Apache24/htdocs/{sitename}"
    ServerName {sitename}
    ServerAlias {sitename}
    
    Options -FollowSymLinks -Indexes -MultiViews
    
    RewriteEngine On

    LogLevel alert rewrite:trace6

    #Just testing to see if the command block is found
    #Note: The log file reports this as a match.
    RewriteCond %{HTTP_HOST} sitename 

    #part 1: IF the URI starts with /page.php...
    #the show stops here...Apache finds no match, with or without the '/'.
    #even though page.php is entered into the browser, it is never evaluated
    RewriteCond %{REQUEST_URI} ^/page.php

    #Part 2: AND there's a query string that matches this pattern  
    #this condition is never reached since Part 1 fails
    RewriteCond %{QUERY_STRING} ^m=[0-9]{1,3}$ 

    #THEN: rewrite the url and go to /homepage.php (forgetting the query)
    RewriteRule (^.$) /homepage.php [R=301,QSD,END]
    
    ErrorLog "logs/sitename_error.log"
    
</VirtualHost>

When I put hostname/page.php?m=150 in the browser, the {REQUEST_URI} line fails to match. When I look at the siteroot_error.log, the first 3 entries in the log look like this (unreadable data removed):

.... init rewrite engine with requested uri /  #WHY / and not /page.php????
.... applying pattern '(^.$)' to uri '/'
.... RewriteCond: input='hostname' pattern='hostname' => matched #Duh!
.... RewriteCond: input='/' pattern='/page.php' => not-matched
.... pass through /
.... init rewrite engine with requested uri /index.php
.... RewriteCond: input='' pattern='^m=[0-9]{1,3}$' => not-matched

entry in the log is evaluating the request '/'. Shouldn't it be evaluating '/page.php' ? In any event, it finds no match so passes '/' along. As a result, apache then appends 'index.php' as that is the first file set in the DirectoryIndex parameter in the server apache config file. And, in this case, there is no index.php or index.html file in the '/' directory, so the request fails.

To my way of thinking the first evaluation that should appear in the log file is the evaluation of '/page.php' and apache should be attempting to match it with the pattern ('/page.php'). What am I missing? Why is rewrite trying to match '/'?

over 4 years ago · Santiago Trujillo
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